in reply to Defining a sub within a sub: OK?
The main problem with nested subs, beyond the misleading apparent scoping of the innermost definition, is that Perl can only handle one level of closure, as (rather obliquely) indicated by the error message:
sub a{ my $x = 'fred'; sub b{ print $x } b(); }; a();; Variable "$x" will not stay shared at ... fred
By the time you leave the definition of sub a(), the variable $x no longer exists, but sub b(), is still callable.
|
|---|