back to notes

Sort by IP Addresses in Perl

my @ips = qw(
172.27.32.200
172.19.32.100
10.1.1.60
192.20.30.133
);

@ips = map {s/\s+//g; $_} sort map {s/(\d+)/sprintf "%3s", $1/eg; $_} @ips;

print join "\n", @ips;

# Output is:
# 10.1.1.60
# 172.19.32.100
# 172.27.32.200
# 192.20.30.133


last updated february 2010