in reply to Re^8: Unable to declare local variable with "use strict".
in thread Unable to declare local variable with "use strict".
The block rovf showed, and which you label a 'closure' doesn't reference a variable outside of its scope.
The scope in which the variable exists ceases to exist long before the function was called. The function definitely references an out-of-scope variable.
[ And JavaFan didn't say otherwise. Oops! ]
$ perl -MO=Concise,foo,-exec -e'{ my $x; sub foo { $x } }' main::foo: 1 <;> nextstate(main 2 -e:1) v 2 <0> padsv[$x:FAKE:] <-- Is "FAKE": closed over 3 <1> leavesub[1 ref] K/REFC,1 -e syntax OK
You seem to think nesting a named sub is the same as nesting blocks, but that's not the case at all. The scope of the outer block still exists when the the inner block is being executed.
$ perl -MO=Concise,-exec -e'{ my $x; { $x } }' 1 <0> enter 2 <;> nextstate(main 4 -e:1) v:{ 3 <{> enterloop(next->b last->b redo->4) v 4 <;> nextstate(main 1 -e:1) v 5 <0> padsv[$x:1,3] vM/LVINTRO 6 <;> nextstate(main 3 -e:1) v 7 <{> enterloop(next->a last->a redo->8) v 8 <;> nextstate(main 2 -e:1) v 9 <0> padsv[$x:1,3] v <-- Not "FAKE": in scope a <2> leaveloop vK/2 b <2> leaveloop vK/2 c <@> leave[1 ref] vKP/REFC -e syntax OK
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^10: Unable to declare local variable with "use strict".
by JavaFan (Canon) on Mar 29, 2010 at 21:05 UTC | |
by ikegami (Patriarch) on Mar 29, 2010 at 21:31 UTC |