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”.


In reply to Re^4: Variable name by JadeNB
in thread Variable name by nsteiner

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.