in reply to Sort in IP in 2 lines.

print sort{($a=~/(\d+(\.\d+){3})/)[0]cmp($b=~/(\d+(\.\d+){3})/)[0]}<>;

Replies are listed 'Best First'.
Re: Re: Sort in IP in 2 lines.
by sauoq (Abbot) on May 30, 2003 at 20:54 UTC

    Uh... that doesn't sort IPs in the way you might expect IPs to be sorted...

    perl -le 'print for sort{($a=~/(\d+(\.\d+){3})/)[0]cmp($b=~/(\d+(\.\d+ +){3})/)[0]} qw(1.2.3.4 1.12.3.4);' 1.12.3.4 1.2.3.4

    In fact, it doesn't do much of anything except a run-of-the-mill asciibetical sort of lines based on the first portion of them that looks somewhat like an IP.

    I can't believe that this has sat around for almost two years without reply... I hope no one out there has actually used it!

    -sauoq
    "My two cents aren't worth a dime.";