Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
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 exploiting the Monastery: (6)
As of 2014-09-20 02:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (151 votes), past polls