Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re^3: Hashes, keys and multiple histogram

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


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

Each array element should be a key except for the first

Maybe I had misread this line when I wrote my previous answer. Possibly you really want something like this:

$hash1{$_}++ for @elements;
Example under the debugger:
DB<1> @elements = qw/ 1 3 5 4 6/; DB<2> $hash1{$_}++ for @elements; DB<3> x \%hash1 0 HASH(0x600509af0) 1 => 1 3 => 1 4 => 1 5 => 1 6 => 1

Replies are listed 'Best First'.
Re^4: Hashes, keys and multiple histogram
by f77coder (Beadle) on Aug 17, 2014 at 13:09 UTC

    Thanks for reply.

    At the end, I would expect 3 histograms with the keys being elements of the array and values equal to the count.

    line = "0 1 6 2 68fd1e64 80e26c9b 1f89b562 e5ba7672"

    0 is the variable for the switch, the rest of the line needs to be put into keys and then count/increment.

    hist1={ "0" => 43, "0468d672" => 1, "05db9164" => 7, "07c540c4" => 2, "0a519c5c" => 1, "0b153874" => 14, "1" => 11, "10" => 1, "14" => 1, "15" => 1, "18" => 1, "1e88c74f" => 2, "1f89b562" => 3, "2" => 9, "241546e0" => 1, "287130e0" => 1, "287e684f" => 1, "2c16a946" => 2, } hist2={ "6c9c9cf3" => 1, "7" => 2, "776ce399" => 4, "7cd19acc" => 1, "8" => 1, "80e26c9b" => 2, "8cf07265" => 2, "8efede7f" => 1, "9b5fd12f" => 1, "ad4527a2" => 1, "ae46a29d" => 1, "b0660259" => 1, "bc6e3dc1" => 1, "be589b51" => 1, "d4bb7bd8" => 3, "d833535f" => 1, "e5ba7672" => 7, "f0cf0024" => 2, } hist3={ "3" => 2, "31" => 1, "3486227d" => 1, "361384ce" => 1, "37e4aa92" => 1, "38a947a1" => 1, "38d50e09" => 1, "3c9d8785" => 1, "4" => 3, "439a44a4" => 1, "5" => 3, "510b40a5" => 1, "5a9ed9b0" => 1, "6" => 1, "64523cfa" => 1, "68fd1e64" => 5, }
      Then I think you really need exactly what I suggested in my second answer. Replace your code by the following one for each of your three hashes:
      $hash1{$_}++ for @elements;
      (changing obviously to the right hash name depending on the switch variable) and I think it should do the trick.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (4)
As of 2024-04-24 11:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found