http://qs321.pair.com?node_id=431764


in reply to Re: sorting ip octets
in thread sorting ip octets

If you dont like using pack. Or you have another type of data in the future, remember than cmp and <=> return 0 if they are the same. See below.

sort { my @a = split(/\./, $a); my @b = split(/\./, $b); $a[0] <=> $b[0] || $a[1] <=> $b[1] || $a[2] <=> $b[2] || $a[3] <=> $b[3] } @list

Replies are listed 'Best First'.
Re^3: sorting ip octets
by Animator (Hermit) on Feb 17, 2005 at 10:15 UTC

    You should read the FMTYWTK about sort...

    Doing it this way will be really slow on large data sets since you are doing lots of splits...

    Note, if you apply the FMTYWTK technique then you get about the same as my post...