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