in reply to How to sort IP addresses
use Socket qw( inet_aton ); use List::MoreUtils qw( apply ); my $file_name = "ipsvisiting.txt"; open (my $fh, '<', $file_name) or die("Unable to open file \"$file_name\": $!\n"); my @sorted = map { substr($_, 4) } sort map { inet_aton($_) . $_ } apply { chomp } <$fh>; print "$_\n" foreach @sorted;
I started writing this when there were no replies, but I got sidetracked. Hopefully, this approach hasn't been suggested already.
I made some change to your code:
|
|---|