Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: Hash of Array references

by sundialsvc4 (Monsignor)
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.


Comment on Re: Hash of Array references

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (3)
As of 2014-09-18 01:36 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (104 votes), past polls