Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer

Re: seeking in hash data structure

by ailivac (Sexton)
on Oct 25, 2006 at 05:10 UTC ( #580490=note: print w/replies, xml ) Need Help??

in reply to seeking in hash data structure

There's a fairly simple algorithm to do this that you can write if you understand how recursion and references work. Your function starts with a reference to the root of the hash, the value to add once you find the right node, and a list of keys to find that node. Shift the first keys from the list and look up that entry in the hash, which gives you a hashref. Call the function again recursively with this new hashref, the same value to add, and the remaining keys. Once there are no more keys, you can add the value to the hashref you have, which will point to the right position in the tree. Use a syntax like $hashref = $hashref->{key} to go down to the next level in the hash. By "non strict references" I assume you meant symbolic references, the ones you can't use with use strict. And no, those won't work, because the hashes are anonymous.

Replies are listed 'Best First'.
Re^2: seeking in hash data structure
by Maze (Sexton) on Oct 26, 2006 at 21:55 UTC
    That is a skillfull method my esteemed monk, but for laziness sake the perl module Data::Diver and the -numerous- SQL interfaces that i've now looked up seem to be the ticket, I think that for practices sake I may write up that algorithm my self, if I get round to it.

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://580490]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (2)
As of 2022-05-19 03:25 GMT
Find Nodes?
    Voting Booth?
    Do you prefer to work remotely?

    Results (71 votes). Check out past polls.