Don't ask to ask, just ask | |
PerlMonks |
Re: Scoping of my with foreach loopby BrowserUk (Patriarch) |
on Mar 07, 2005 at 19:29 UTC ( [id://437293]=note: print w/replies, xml ) | Need Help?? |
It doesn't make a lot of sense to use a loop variable that was previously declared, because the one that gets used within the loop is (temporarally), an entirely different variable, despite that it has the same name:
Doing so tends to make look as if $i will retain the last value used in the loop, but as you can see, it doesn't. It caught me out a couple of times and is something that I hope will not persist into Perl6. In fact, I think I would change it in perl 5.10. Any code that got bitten by the change in behaviour would be better changed anyway. Examine what is said, not who speaks.
Silence betokens consent.
Love the truth but pardon error.
In Section
Seekers of Perl Wisdom
|
|