in reply to Re^3: Variable name
in thread Variable name

Which explains it, (though it doesn't exactly satisfy the concept of least surprise), as the globals also existed despite that I had created similarly named lexicals. Which, (apparently naively), I expected to override the globals at the local scope.
I think that it's important to note that lexicals do override globals—more generally (and more precisely), that the variable declared later overrides the one declared earlier—unless you explicitly ask for globals. Of course, no one would expect $::foo to access a lexical. Similarly, since ${'foo'} requires us to look up a variable by name, rather than location, and since the only way to find variables by name is in the symbol table, we can't possibly 1 get a lexical this way.

(I know that you know this, but I worry about casual future readers thinking that you're suggesting that globals always override lexicals.)

1 As almut correctly points out below, “can't possibly” is almost never correct about Perl. I probably ought to have said “shouldn't”.

Replies are listed 'Best First'.
Re^5: Variable name
by BrowserUk (Patriarch) on Dec 08, 2008 at 22:58 UTC

    A point worth making and well made.

    The naivety was mine. For which my only excuse is that I've so rarely had occasion to use symbolic references that I didn't think about it that way.


    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.
Re^5: Variable name
by almut (Canon) on Dec 08, 2008 at 23:12 UTC
    since the only way to find variables by name is in the symbol table, we can't possibly get a lexical this way.

    In theory, the mechanism used by PadWalker could be used to lookup lexicals by name... it just isn't being done with symbolic references.

    #!/usr/bin/perl use strict; use warnings; use PadWalker; my $foo="foo"; my $bar="f"; my $p = PadWalker::peek_my(0); print ${$p->{'$'.$bar.'oo'}}, "\n"; # "foo"