Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Re: Pingu can't sort a hash

by seanbo (Chaplain)
on Nov 27, 2001 at 21:04 UTC ( [id://127832]=note: print w/replies, xml ) Need Help??


in reply to Pingu can't sort a hash

Here is something I did once while sorting a hash keyed by IP address. Just to show another way of sorting things out. The results above are both very good replies and are detiled to your specific question, but for what it's worth...here is my code.
sub sort_ips() { my %counts; my $hash_ref = shift; print "Subnet\t\tCount\n"; foreach my $ip(keys(%$hash_ref)) { my $subnet = pack 'C3', split /\./, $ip; $counts{$subnet}++; } foreach my $subnet(sort keys(%counts)) { print join '.', unpack 'C3', $subnet; print ":\t$counts{$subnet}"; print "\n"; } print "\n"; }


seanbo

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (7)
As of 2024-04-16 09:09 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found