Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
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 studying the Monastery: (8)
As of 2016-06-24 22:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My preferred method of making French fries (chips) is in a ...











    Results (322 votes). Check out past polls.