There is really (for some value of "really") only one symbol table!

Not really — or only if you add "per namespace/package". Somewhat simplified, you can think of it as a nested hash-of-hashes structure. For example, the package(s) Foo::Bar would be represented like

%:: = ( 'Foo::' => { 'Bar::' => { varname => typeglob, ... }, ... }, ... );

The main difference is that the values associated with the packagename keys like 'Foo::' aren't simple hashrefs, but rather typeglobs, whose hash slot points to the actual symbol table hash. But Perl has some DWIM magic in place for globs, i.e. if you treat it as a hashref, you'll get its hashref entry, which is why you can write $::{'Foo::'}{'Bar::'}{varname}, as if it were a HoHoH.

I need to rewrite this entire node.

Not necessarily  (all I would change is ${*{"${ns}\::foo"}} into the simpler ${"$ns\::foo"} or ${"${ns}::foo"} ).  Symbolic references are there for a reason.  While I would probably use the "non-symbolic" approach for simple static structures like your Teddy:: example, I would rather use symbolic references for more complex/arbitrary structures, (like you might get from caller), because creating a HoHo... access from something variable-depth like Foo::Bar::Baz::... is much too much work compared to locally saying no strict 'refs', and then simply using the string "Foo::Bar::Baz::..." as is...


In reply to Re^5: Stashing a Package Variable by Reference by almut
in thread Stashing a Package Variable by Reference by Xiong

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.