Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: Ipsort

by runrig (Abbot)
on Dec 08, 2000 at 06:35 UTC ( #45676=note: print w/ replies, xml ) Need Help??


in reply to Ipsort

my @ips = qw(100.100.100.100 1.1.1.1); my @sorted = map { $_->[0] } sort { $a->[1] cmp $b->[1] } map { [ $_, sprintf("%03d" x 4, split(/\./, $_)) ] } @ips; # OR my @sorted = map { $_->[0] } sort { $a->[1] cmp $b->[1] } map { [$_, pack("C*", split(/\./, $_))] } @ips;


Comment on Re: Ipsort
Download Code
Re: Re: Ipsort
by I0 (Priest) on Dec 17, 2000 at 21:22 UTC
    #or my @sorted = map {join".",unpack'C*',$_} sort map{pack"C*",split/\./} +@ips; #or, in v5.6.0 my @sorted = map {sprintf"%vd",$_} sort map{eval "v$_"} @ips;

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://45676]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (9)
As of 2014-07-29 06:36 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (211 votes), past polls