in reply to About the closure issue in nested sub

The answer is that Perl 5 really doesn't have "nested subs".

Subs live in the symbol table, not inside a lexical scope, so the "inner" sub isn't really inside the "outer" sub -- it is in the symbol table, and thus can be called before the outer sub is called.

The fact that perl still allows you to write a sub inside a sub comes from a cheat that makes it possible, but that cheat doesn't extend to the closure semantics you seem to expect.

(The experience from watching and patching Perl 6 compilers shows that nested named subs and correct closure semantics are a pain to get right (if the inner sub is visible outside the outer sub), no wonder the perl 5 folks haven't felt like fixing this).

  • Comment on Re: About the closure issue in nested sub