The secret is to use a sort function. Er, my mistake, you're using one already ... you just need to do a few more comparisons. Perl doesn't have a built in octet comparator for some reason. I use the following little guy a lot, so I just cut and pasted it here. It may help. I call it my ipsort_pipet.
my @lines = <STDIN>; print $_ for sort cmp_ip @lines; sub cmp_ip { my @c = split /\./, $a; my @d = split /\./, $b; for(0.. 3) { return $c[$_] <=> $d[$_] if $c[$_] != $d[$_] } return $a cmp $b }
-Paul
In reply to Re: How to sort IP addresses
by jettero
in thread How to sort IP addresses
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |