Yes, almut, I completely missed what you were doing!

Study-up on the web is amazingly difficult on this topic. Source after source discusses "symbol tables" (plural) and forks every other source, contrasting package variables vs lexicals; our vs local vs doing nothing at all; and of course speaking briefly about symbolic references before telling how to use strict so that they can't be used at all. Some sources go into bloody detail about the structure of a typeglob; I even found an interesting explanation of the internal C representation of variables.

There is really (for some value of "really") only one symbol table! Careful reading of Camel tells:

As it happens, the main symbol table contains all other top-level symbol tables, including itself...
<cite>Programming Perl 2nd ed. 5.1.1</cite>

I've experimented a bit with this now. Your code works and it's a vast improvement over what I had. This works too, under strict and warnings:

my $ns = 'Teddy::'; my $var = 'foo'; ${ $::{$ns}{$var} } = 'cheese';

... which isn't a symbolic reference??

I need to rewrite this entire node. Meanwhile, I bow to almut's superior code-fu.

- the lyf so short, the craft so long to lerne -

In reply to Re^4: Stashing a Package Variable by Reference by Xiong
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.