Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

RE: Sorting a list of IP addresses (aka Why I hate Big O)

by dws (Chancellor)
on Aug 03, 2000 at 04:05 UTC ( #25885=note: print w/ replies, xml ) Need Help??


in reply to Sorting a list of IP addresses (aka Why I hate Big O)

It doesn't change the O'ness, but this looks like a job for the Orcish maneuver.

my %cache = ();
my @sorted = sort {
        $cache{$a} ||= pack('C4' => $a =~ /(\d+)\.(\d+)\.(\d+)\.(\d+)/);
        $cache{$b} ||= pack('C4' => $b =~ /(\d+)\.(\d+)\.(\d+)\.(\d+)/);
        $cache{$a} cmp $cache{$b};
} @unsorted;


Comment on RE: Sorting a list of IP addresses (aka Why I hate Big O)

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (13)
As of 2014-09-03 06:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite cookbook is:










    Results (35 votes), past polls