Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re: Obtaining number of counts per each name in hash

by jeffa (Bishop)
on Jul 07, 2015 at 19:20 UTC ( [id://1133597]=note: print w/replies, xml ) Need Help??


in reply to Obtaining number of counts per each name in hash

You want to increment the value of the key as each occurrence is found:

$name{$hashkey}++;
And then later:
print "$_ $name{$_}\n" for keys %name;

You could trim up your code a bit as well:

if ($line =~ /(\S+)/) { $name{$1}++; }

jeffa

L-LL-L--L-LL-L--L-LL-L--
-R--R-RR-R--R-RR-R--R-RR
B--B--B--B--B--B--B--B--
H---H---H---H---H---H---
(the triplet paradiddle with high-hat)

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (6)
As of 2024-04-23 14:17 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found