Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re: How do I extract the number of times a value appears in a hash?

by BlaisePascal (Monk)
on Sep 01, 2000 at 00:53 UTC ( [id://30633]=note: print w/replies, xml ) Need Help??


in reply to How do I extract the number of times a value appears in a hash?

Is the "IP_Address:size" blocks the hash values, or the hash keys?

Assuming the the IP_Address:size blocks are the hash values (say, you were keying off of a connection ID, or something), then you could do something like:

my %counts; my %sizes; for (values %inhash) { my ($ip, $size) = split /:/; next unless defined $ip; $counts{$ip}++; $sizes($ip)+= $size; } for $ip (keys $counts) { my ($count, $size) = ($counts{$ip},$sizes{$ip}; print "IP Address $ip appeared $count times, for a total size of $si +ze\n"; }
Does that help?
  • Comment on Re: How do I extract the number of times a value appears in a hash?
  • Download Code

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (5)
As of 2024-04-25 11:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found