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.
In reply to Re^4: Stashing a Package Variable by Reference
by Xiong
in thread Stashing a Package Variable by Reference
by Xiong
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |