may I add that a Schwartzian Transform might help speeding up the sort. Then the split doesn't have to be done over and over again. This leads to
my @sorted_keys = map {$_->[0]} sort {$a->[1] <=> $b->[1] || $a->[2] <=> $b->[2] || $a->[3] <=> $b->[3] || $a->[4] <=> $b->[4]} map { [ $_, split /\./ ] } keys %ip; foreach (@sorted_keys) { # do something }
Instead of splitting one could also use the MZSanford's suggestion and sort on a zeropadded string in the transformation.
Update:
The code above was written to resemble as closely as possible davorg's original subroutine. For better solutions (in terms of performance) see blakem's and davorg's responses to my post.
-- Hofmator
In reply to Re: Re: Sorting a hash of IP addresses?
by Hofmator
in thread Sorting a hash of IP addresses?
by mnperez
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |