in reply to Re: ip sorting
in thread ip sorting
Now this piece of code works properly (I tested the modified version).sort {$a cmp $b}
,which Perl interprets as a string, not an unsigned long.struct in_addr { union { struct { u_char s_b1,s_b2,s_b3,s_b4; } S_un_b; struct { u_short s_w1,s_w2; } S_un_w; u_long S_addr; } S_un; }
use strict; use Socket qw( inet_aton inet_ntoa); local $, = $/; print map { inet_ntoa($_) } sort { $a cmp $b } map { chomp; inet_aton($_) } <DATA>; print $/; __DATA__ 128.1.1.0 127 23.4.5.6 255.255.255.255 45.27.128.0 localhost
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Re: ip sorting
by Anonymous Monk on Mar 24, 2003 at 00:06 UTC |