Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: sorting ip octets

by TedPride (Priest)
on Feb 16, 2005 at 19:13 UTC ( #431692=note: print w/replies, xml ) Need Help??


in reply to sorting ip octets

Or, a somewhat more readable version:
my @ips = <DATA>; $_ = sprintf("%03d.%03d.%03d.%03d", split /\./) for (@ips); @ips = sort @ips; $_ = sprintf("%d.%d.%d.%d", split /\./) for (@ips); print join "\n", @ips; __DATA__ 127.0.0.1 10.129.30.5 10.129.30.2 255.255.255.255 10.109.30.5 142.222.130.23 10.109.1.1 142.222.87.30
Basically, you convert to fixed width (3 chars per octet), sort, and convert back to the original unpadded numbers.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (2)
As of 2022-08-18 20:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?