XP is just a number | |
PerlMonks |
Re^3: foreach-loop-local var in subby LanX (Saint) |
on Jan 22, 2013 at 03:24 UTC ( [id://1014546]=note: print w/replies, xml ) | Need Help?? |
From perlsyn#Foreach Loops
Otherwise, the variable is implicitly local to the loop and regains its former value upon exiting the loop. If the variable was previously declared with "my", it uses that variable instead of the global one, but it’s still localized to the loop. If you also check the references you will see that the '$i' are pointing to different locations.
OUTPUT
That's why PBP says to always use lexical loop vars in foreach!
Cheers Rolf
In Section
Seekers of Perl Wisdom
|
|