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