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

Many thanks Laurent for the code. The reason I'd like to keep the histograms separate is now I need to operate on the individual hash arrays. I need to find what is only in %hist1, only in %hist2, only in hist3% and then find intersections and probabilities on the intersection of %hist1,%hist2, %hist2,%hist3, and %hist1/%hist3

Are there bindings to do statistical operations on the hash values?

  • Comment on Re^2: Hashes, keys and multiple histogram

Replies are listed 'Best First'.
Re^3: Hashes, keys and multiple histogram
by Laurent_R (Canon) on Aug 17, 2014 at 16:46 UTC
    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.

Re^3: Hashes, keys and multiple histogram
by AnomalousMonk (Archbishop) on Aug 18, 2014 at 14:52 UTC