123.456.789.12 12.345.67.19 12.345.67.18 12.345.66.20
I am trying to get a Perl script that will sort these in terms of each set of numbers from smallest to largest. I.e., the first set of numbers before the first period are used to sort. Then, if there are matches, the second set of numbers are compared and sorted. And so on. So, in the above case, the sort would result in:
12.345.66.20 12.345.67.18 12.345.67.19 123.456.789.12
I tried the following:
#!/usr/bin/perl open (FILE,"ipsvisiting.txt"); while (<FILE>) { $j[$i++] = $_; } close FILE; sub nummer { $a <=> $b; } @sorted = sort nummer @j; foreach $s (@sorted) { print $s; }
This "seems" to do some sorting, but it results in things like this:
12.345.111.3 12.345.111.26 12.345.111.24 12.345.111.5 12.345.111.4
In other words, it seems to stop working after it reaches the last set of numbers.
Any idea how to fix this?
In reply to How to sort IP addresses by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |