Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re^3: Hashes, keys and multiple histogram

by Laurent_R (Canon)
on Aug 17, 2014 at 16:46 UTC ( [id://1097740]=note: print w/replies, xml ) Need Help??


in reply to Re^2: Hashes, keys and multiple histogram
in thread Hashes, keys and multiple histogram

Well, I suspect that the modules with which you are going to analyze your data probably expect hash references (instead of hashes). If such is the case, then, instead of passing \%hist1, you can just pass to your function $hist{1}, which happens to contain a reference to the relevant sub-hash. For example, $hist{5} contains a hash ref pointing to the following data structure:
0 HASH(0x6005200f0) 0 => 5 '0468d672' => 1 '05db9164' => 2 '0b153874' => 2 5 => 1 '6c9c9cf3' => 1 '776ce399' => 2
If it turns out you need to pass an actual hash (and not a hash ref), then just dereference it by passing, for example, %{$hist{5}} to the function.

Update: Maintaining 3 or 4 hashes containing essentially identical sets of data is usually a bad idea, because it scales up very badly when you need to add an additional data set, and the code is much longer (see the difference between my two sample programs) and it is therefore harder to maintain: if you need a change to be done, you need to do it in several different places and the chances are high that you'll forget one place.

I can understand that using nested data structure may be challenging for a beginner, but you'll have to learn them anyway at one point (if you continue to do even relatively occasional programming), so why not start learning that right away? You know by now that, if you encounter difficulties, you'll easily get help from many monks here.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others learning in the Monastery: (3)
As of 2024-04-24 19:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found