in reply to Re^2: Inner subroutines?
in thread Inner subroutines?
It's got nothing to do with BEGIN being sub-like. Inner subs would have to capture every time the outer sub is called. But since there are no private subs in Perl, there isn't necessarily any executing outer sub to capture from.
is basicallysub outer { sub inner { } }
Replace it withsub outer { BEGIN { *inner = sub { }; } }
sub outer { *inner = sub { }; }
and inner will capture properly for an inner sub. Of course, problems will still ensue if you call inner() from outside of outer(). To solve that, you'd need a language feature such as
sub outer { my sub inner { } }
|
|---|