Hi, now that you have fully explained what you want, how about this:
use strict; use warnings; use Data::Dumper; ########################################## my (%hist1, %hist2, %hist3); my @required_keys; while (<DATA>) { chomp; my @element = split; my $col0= shift @element; if ($col0 == 1){ $hist1{$_}++ for @element; } elsif ($col0 == 0){ $hist2{$_}++ for @element; } elsif ($col0 == 5){ $hist3{$_}++ for @element; } else { #do stuff here when all else fails, undef/NaNs print "WTF \n"; } }; print Dumper \%hist1; # using your __DATA__ section, not repeated here for brevity

which produces this for the %hist1 hash:

$VAR1 = { '2c16a946' => 1, '2' => 2, '361384ce' => 1, '287130e0' => 1, '1' => 2, '68fd1e64' => 2, 'e5ba7672' => 2, '0' => 6, '07c540c4' => 1, '1f89b562' => 2, '0b153874' => 1, 'be589b51' => 1, '4' => 1, 'd4bb7bd8' => 1, '241546e0' => 1, '38a947a1' => 1, '5' => 1, '38d50e09' => 1 };

I tried to keep the code above relatively close to what you had, but I would probably change the code to use only one hash of hashes, rather than three different hashes, leading to much shorter code:

use strict; use warnings; use Data::Dumper; my %hist; while (<DATA>) { chomp; my ($col0, @element) = split; $hist{$col0}{$_}++ for @element; }; print Dumper \%hist; # not repeating the __DATA__ section here
Which produces the following output.

$VAR1 = { '1' => { '2c16a946' => 1, '2' => 2, '361384ce' => 1, '287130e0' => 1, '1' => 2, '68fd1e64' => 2, 'e5ba7672' => 2, '0' => 6, '07c540c4' => 1, '1f89b562' => 2, '0b153874' => 1, 'be589b51' => 1, '4' => 1, 'd4bb7bd8' => 1, '241546e0' => 1, '38a947a1' => 1, '5' => 1, '38d50e09' => 1 }, '0' => { '8efede7f' => 1, 'ad4527a2' => 1, '7' => 2, 'b0660259' => 1, '3c9d8785' => 1, '2' => 7, '287e684f' => 1, '1' => 5, '18' => 1, 'e5ba7672' => 5, '07c540c4' => 1, 'f0cf0024' => 2, '0b153874' => 11, '776ce399' => 2, '80e26c9b' => 2, '64523cfa' => 1, '14' => 1, '7cd19acc' => 1, 'bc6e3dc1' => 1, '10' => 1, '31' => 1, '37e4aa92' => 1, '510b40a5' => 1, '9b5fd12f' => 1, '2c16a946' => 1, 'd833535f' => 1, 'ae46a29d' => 1, '68fd1e64' => 3, '0a519c5c' => 1, '0' => 16, '6' => 1, '1e88c74f' => 2, '1f89b562' => 1, '3' => 2, '8cf07265' => 2, '3486227d' => 1, '5a9ed9b0' => 1, '05db9164' => 5, '15' => 1, '8' => 1, '4' => 2, '439a44a4' => 1, 'd4bb7bd8' => 2, '5' => 1 }, '5' => { '0b153874' => 2, '0' => 5, '0468d672' => 1, '776ce399' => 2, '6c9c9cf3' => 1, '05db9164' => 2, '5' => 1 } };

In reply to Re: Hashes, keys and multiple histogram by Laurent_R
in thread Hashes, keys and multiple histogram by f77coder

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.