in reply to Re: Re: Re: NEWBIE Brain Teaser
in thread NEWBIE Brain Teaser

i am not a "more monkish Monk", but i did get curious about this behavior of foreach. This is an alias (example modified from _Advanced Perl Programming_ (O'rielly) by Sriram Srinivasan):
$a = 10; # saclar a @a = (1, 2, 3); # array a *b = *a; # aliases b to a $a++; # increments $a :) $b++; # same as saying $a++ print "$b, $a"; # prints: 12 12 @b[0] = 4; # same as saying $a[0] = 4
as you can see, the aliasing on line 3 makes any manipulation of $b, @b or %b manipulate $a, @a, %a respectively. hope this helps and is not too confusing. if i'm wrong, tell me :)