Hi Shmuel,
On Wed, 1 May 2013 17:09:34 +0900
Shmuel Fomberg <[email protected]> wrote:
> 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;
Please don't lexicalise $a and $b:
http://perl-begin.org/tutorials/bad-elements/#vars-a-and-b
Regards,
Shlomi Fish
> print "a=$a, b=$b\n";
> }
>
> Shmuel.
--
-----------------------------------------------------------------
Shlomi Fish http://www.shlomifish.org/
What Makes Software Apps High Quality - http://shlom.in/sw-quality
Logic sucks. Morality sucks. Reality sucks. Deal with it!
Please reply to list if it's a mailing list post - http://shlom.in/reply .
_______________________________________________
Perl mailing list
[email protected]
http://mail.perl.org.il/mailman/listinfo/perl