http://qs1969.pair.com?node_id=580422

Maze has asked for the wisdom of the Perl Monks concerning the following question:

a reccuring problem for me seems to be a way to acquire a reference to an arbritrary point in a data structure comprised of nested hashes.

suppose for example you have:

my %hash = ( 'company' => { 'microsoft' => {'applications' => {'windows' => 'operating system', 'office' => 'o +ffice suite'} ,'people' => {'bill gates' => 'chair man'} }, 'sun microsystems' => {'applications' => {'solaris' => 'operating system', 'star office' => 'office suite'} }, 'cross over' => {} } );
or something similar, now with this hash you could create a subroutine for each level of the data structure, say "sub add_company" or "sub add_application" but ideally what id like to be able to do is to seek to any level of the data structure and just throw in a value

to do that I suppose what you'd need to do is create a sub which takes a set of names to "crawl" along in the hash data structure, this would then find a reference to the part of the data structure you want, and then perform a set of operations to the 'location' referred to, independent of where that is.

with this you could then say something like:

add_to_hash(\%hash,'scalar','companies-microsoft-people-steve ballmer' +,'bills bulldog') #and you suddenly decide to have another category add_to_hash(\%hash,'list','companies-cross over-supports','iTunes','ph +oto shop') #or something more elegant
perhaps the above example could be perfomred using hash::merge, but still having an ability to find an arbitrary point in a data structure that can be then passed to a function would be immensely helpful, and if it seems like i'm trying to use hash structures like file hierachies, well yes, that's exactly right

the question i ask is, how to do it, I've tried using recursive hash references like

 \$hashref = $%hashref{foobar} 
and perl seems to really not like that, same with trying to construct the name of the hash from the root of the structure via non strict references

what am I missing?, any syntatic sugar, or a modules that I really should get to grips with