Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw

Re: Hash of Array references

by sundialsvc4 (Abbot)
on Aug 04, 2014 at 14:38 UTC ( #1096134=note: print w/replies, xml ) Need Help??

in reply to Hash of Array references

I prefer to think of data-structures like this as complex ”records” that might be “indexed” in a number of different ways.   For example, define a single (anonymous) hashref to be your “record,” with a key for each “field” and a value that consists, as the case may be, either of a scalar or an array of values.   Your basic data store is an array of those hashrefs.

Then, for all of the ways that I need to locate those records ... well, here you have a pragmatic choice.

One way is to use additional hashes as indexes:   the keys are values being sought, and the values are either a single scalars (references are scalars), or an array of references.   You look up the key, then you have a reference to the record(s) that match that key.

But, pragmatically, you can also often just-as-well use the grep function to loop through the entire array, brute-force.   It is memory, after all, albeit virtual, but if you have “gobs of RAM,” it’s usually fast-enough just to search for whatever you want each time.

Still, when it comes down to locating “a record,” I do eventually want to come to that:   a single data-structure (a hashref), which, by itself and self-contained, contains all of whatever I need to know about that Thing.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1096134]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (13)
As of 2018-03-20 14:12 GMT
Find Nodes?
    Voting Booth?
    When I think of a mole I think of:

    Results (253 votes). Check out past polls.