in reply to Re^3: Closures & aliases
in thread Closures & aliases

I see.

So, with global variables, like in

$a = 2; sub f { print $a; } { local $a = 5; f; }'
or
$a = 2; sub f { print $a; } for $a (5) { f; }
we get 5 as the result, as perl localizes $a dynamically.

However, if you put my before $a, perl can not localize the variable dynamically. In the first case, local raises an error, as Larry knows Perl can't localize a my, so he explicitly denied it. In the second case, however, if you put my before $a in the beginning, for will not carp (that would be a too bad restriction), but instead localizes $a in the wrong way.