in reply to Re: Doubly-nested deeply bound variable is undefined
in thread Doubly-nested deeply bound variable is undefined
Right after the part you mentioned, perlsub says this:
This doesn't mean that a my variable declared in a statically enclosing lexical scope would be invisible. Only dynamic scopes are cut off. For example, the bumpx() function below has access to the lexical $x variable because both the my and the sub occurred at the same scope, presumably file scope.
I thought that since the lexical scope of $x includes the body of bumpx(), any closures created inside bumpx should also have access to $x -- and they do, kinda. But it seems like bumpx() (or foo(), in my case) has to be "reminded" that $x is in its scope, otherwise the inner sub doesn't get access.my $x = 10; sub bumpx { $x++ }
|
|---|