in reply to Variable will not stay shared in subroutine
Juerd answered this, but I just wanted to point out that I find the docs a bit misleading on this point. It refers to inner and outer subroutines, but does not make it clear that subs cannot be lexically scoped (I understand that this may change in Perl6). Thus, anytime I see subroutines nested like this, I look for errors in the code stemming from the misunderstanding. Looks like you found one of those errors :)
Subroutines are entries in the current namespace's symbol table (in a typeglob slot) and this does not allow for nesting. As the docs explain, this can be gotten around by using an anonymous subroutine because these get stuffed in a scratchpad, thus making them lexically scoped.
Cheers,
Ovid
Join the Perlmonks Setiathome Group or just click on the the link and check out our stats.
|
|---|