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
    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.
    Yes. What's your point here? I don't think I claimed the function doesn't.

    Let me requote doug:

    Any block that creates scoped variables is a closure in my book.
    And the block discussed here is the following posted by rovf:
    { # closure starts here my $shared_variable; sub ref_test1 { ... } sub ref_test2 { ... } }
    Or are you going to retract your retraction about the outer block being a closure?
    You seem to think nesting a named sub is the same as nesting blocks
    Where did you get that idea from? Why does that even matter in my argument with doug that a closure is something else than just a block giving scope to a variable?
      Argh, I just can't read straight today. Sorry.