in reply to Sorting ip addresses quickly

probably, the fastest way to sort IPv4 addresses in Perl is to use Sort::Key::IPv4:
use Sort::Key::IPv4 qw(ipv4sort); my @ip = qw(192.168.1.1 10.0.0.1 127.0.0.1 ...); my @sorted = ipv4sort @ip;
See also this node: Sorting IP addresses, lots of them, quickly.

Replies are listed 'Best First'.
Re^2: Sorting ip addresses quickly
by Anonymous Monk on Nov 24, 2010 at 13:43 UTC
    print sort map { s/(\d+)/$1/eg ; $_ } <DATA>; __DATA__ 192.168.7.10 192.168.1.2 192.168.6.10 10.10.254.253
      obviously that doesn't work:
      print sort map { s/(\d+)/$1/eg ; $_ } <DATA>; __DATA__ 192.168.6.10 10.10.254.253 10.10.254.3
        To make it work you'd need to use something like
        print map { $$_[0] } sort { $$a[1] <=> $$b[1] } map { [ $_, join '', map { sprintf '%03d', $_ } /(\d+)/g ] } <DATA>; __DATA__ 192.168.6.10 10.10.254.253 10.10.254.3
        update: oh look, thats what the root post is about, lol