Hi

I need a bit more help on dealing with hashes and keys, I've tried reading the FAQ.

From a previous questions, http://perlmonks.org/index.pl?node_id=1096042 some great help from Athanasius but now I need to modify the code for multiple histograms.

I've tried many combination of hashes to arrays, keys, push… I don't understand why the keys aren't being updated with the new values?

Any help greatly appreciated.

use 5.12.0; use strict; use warnings; use Data::Dump; use Data::Dumper; ########################################## system('clear'); # 1. Configuration my @required_keys; my %hist1 = map { $_ => 0 } @required_keys; my %hist2 = map { $_ => 0 } @required_keys; my %hist3 = map { $_ => 0 } @required_keys; while (my $line = <DATA>) { chomp($line); my @element = split (/ +/,$line); my $col0= shift @element; #use element[0] as switch and drop from hi +stogram if( $col0==1){ %hist1 = map { $_ => 0 } @element; }elsif( $col0==0){ %hist2 = map { $_ => 0 } @element; }elsif( $col0==5){ %hist3 = map { $_ => 0 } @element }else{ #do stuff here when all else fails, undef/NaNs print "WTF \n"; } }; dd \%hist1; # Verify hash contents dd \%hist2; # Verify hash contents dd \%hist3; # Verify hash contents __DATA__ 0 1 0 2 68fd1e64 80e26c9b 1f89b562 e5ba7672 0 2 1 2 68fd1e64 f0cf0024 0b153874 07c540c4 0 2 14 2 287e684f 0a519c5c 0b153874 8efede7f 0 0 0 0 68fd1e64 2c16a946 0b153874 1e88c74f 0 3 0 0 8cf07265 ae46a29d 0b153874 1e88c74f 5 0 0 0 05db9164 6c9c9cf3 0b153874 776ce399 0 0 0 1 439a44a4 ad4527a2 0b153874 776ce399 1 1 0 0 68fd1e64 2c16a946 1f89b562 e5ba7672 0 0 8 31 05db9164 d833535f 0b153874 e5ba7672 0 0 1 2 05db9164 510b40a5 0b153874 d4bb7bd8 5 0 0 5 05db9164 0468d672 0b153874 776ce399 0 0 6 7 05db9164 9b5fd12f 0b153874 d4bb7bd8 1 0 0 0 241546e0 38a947a1 1f89b562 e5ba7672 1 0 5 4 be589b51 287130e0 361384ce 07c540c4 0 0 4 4 5a9ed9b0 80e26c9b 0b153874 3486227d 0 0 18 1 05db9164 bc6e3dc1 64523cfa 776ce399 1 1 2 2 68fd1e64 38d50e09 0b153874 d4bb7bd8 0 0 0 5 8cf07265 7cd19acc 0b153874 e5ba7672 0 0 2 10 05db9164 f0cf0024 37e4aa92 e5ba7672 0 7 3 15 3c9d8785 b0660259 0b153874 e5ba7672

the output

{ "0b153874" => 0, "1" => 0, "2" => 0, "38d50e09" => 0, "68fd1e64" => 0, "d4bb7bd8" => 0, } { "0b153874" => 0, "15" => 0, "3" => 0, "3c9d8785" => 0, "7" => 0, "b0660259" => 0, "e5ba7672" => 0, } { "0" => 0, "0468d672" => 0, "05db9164" => 0, "0b153874" => 0, "5" => 0, "776ce399" => 0, }

In reply to 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.