Hi Chanan.
On Wed, May 1, 2013 at 5:06 PM, Chanan Berler wrote:
> Quick Perl question: Why I can not do something like this?
> my @arr = ((10,20), (100,200), (111,222));
>
> foreach my ($a,$b) (@arr)
> {
> print "a=$a, b=$b\n";
> }
>
Perl just doesn't support this syntax. Your array will be flatted, and
foreach get one variable at a time.
you can do this:
my @arr = ([10,20], [100,200], [111,222]);
foreach my $rec (@arr)
{
my ($a, $b) = @$rec;
print "a=$a, b=$b\n";
}
Shmuel.
_______________________________________________
Perl mailing list
[email protected]
http://mail.perl.org.il/mailman/listinfo/perl