http://www.perlmonks.org?node_id=25885


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)