⭐ in reply to How do I extract the number of times a value appears in a hash?
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:
Does that help?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"; }
|
|---|