in reply to Re: Re: Variable scoping outside subs
in thread Variable scoping outside subs

Hi welchavw, thanks for pointing out that my variables are not inserted into symbol table, instead they are inserted into scratchpads. There are a few excellent references on this topic:

1. Advanced Perl Programming (Oreilly)

The my variables are inserted into the 'scratchpad' of the scope, not the package symbol table.

2. Perl lexical my variables.

The my operator declares the listed variables to be lexically confined to the enclosing block, ...

...

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.

my $x = 10; sub bumpx { $x++ }