in reply to Scoping of my with foreach loop
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:
my $i = -23; for $i ( 1 .. 10 ) { print $i; last if $i == 5; } print $i; 1 2 3 4 5 -23
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.
|
|---|