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

Roger,

I really like most of your explanation, which is much clearer than my attempt, but I am not sure that I agree completely. Lexicals are not inserted into any symbol table as far as I know, so I think that portion of the explanation may be erroneous.

,welchavw

Replies are listed 'Best First'.
Re: Re: Re: Variable scoping outside subs
by Roger (Parson) on Oct 28, 2003 at 03:13 UTC
    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++ }