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

In reply to Re^9: Unable to declare local variable with "use strict". by ikegami
in thread Unable to declare local variable with "use strict". by mr_p

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.