Jeremy Kister wrote:
Gunnar Hjalmarsson wrote:
my @unsorted = (
'5 127.0.0.1',
'10 127.0.1.1',
'5 27.0.0.1',
'6 10.0.0.1',
'1 17.0.0.1',
'5 209.0.0.1',
);
my @sorted = map { $_->[0] } sort {
$a->[1] <=> $b->[1]
||
$a->[2] <=> $b->[2]
||
$a->[3] <=> $b->[3]
||
$a->[4] <=> $b->[4]
||
$a->[5] <=> $b->[5]
} map { [ $_, split /[. ]/ ] } @unsorted;
wild.. But since the data is already in a hash,
Didn't know that was a prerequisite.
are you suggesting to first loop through the hash, pushing the data
into an array, and then running the sort?
No, the point was to show that it can be done with one sort. Given the
hash you can do:
print "$hash{$_} $_\n" for map { $_->[0] } sort {
$hash{ $a->[0] } <=> $hash{ $b->[0] }
||
$a->[1] <=> $b->[1]
||
$a->[2] <=> $b->[2]
||
$a->[3] <=> $b->[3]
||
$a->[4] <=> $b->[4]
} map { [ $_, split /\./ ] } keys %hash;
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>