F
Frank
Hi,
I've been trying to sort an hash on multiple items, but at the moment
with no success.
I got this script:
%hash = (
'one' =>
{'1'=>'a','2'=>'m'},
'two' =>
{'1'=>'a','2'=>'k'},
'thr' =>
{'1'=>'b','2'=>'b'},
'fou' =>
{'1'=>'c','2'=>'l'},
'fiv' =>
{'1'=>'a','2'=>'d'},
'six' =>
{'1'=>'a','2'=>'f'},
'sev' =>
{'1'=>'b','2'=>'f'},
'eig' =>
{'1'=>'a','2'=>'e'},
);
%hash_sort = sort {
$hash{$a}{'1'} cmp $hash{$b}{'1'} || $hash{$a}{'1'} cmp $hash{$b}{'2'}
} keys(%hash);
foreach $key(%hash_sort) {
print "Test: ($key) ".$hash{$key}{'1'}." - " . $hash{$key}{'2'} . "\n";
}
But I seems to just return it in some random order.
What could be wrong?
Regards,
Frank
I've been trying to sort an hash on multiple items, but at the moment
with no success.
I got this script:
%hash = (
'one' =>
{'1'=>'a','2'=>'m'},
'two' =>
{'1'=>'a','2'=>'k'},
'thr' =>
{'1'=>'b','2'=>'b'},
'fou' =>
{'1'=>'c','2'=>'l'},
'fiv' =>
{'1'=>'a','2'=>'d'},
'six' =>
{'1'=>'a','2'=>'f'},
'sev' =>
{'1'=>'b','2'=>'f'},
'eig' =>
{'1'=>'a','2'=>'e'},
);
%hash_sort = sort {
$hash{$a}{'1'} cmp $hash{$b}{'1'} || $hash{$a}{'1'} cmp $hash{$b}{'2'}
} keys(%hash);
foreach $key(%hash_sort) {
print "Test: ($key) ".$hash{$key}{'1'}." - " . $hash{$key}{'2'} . "\n";
}
But I seems to just return it in some random order.
What could be wrong?
Regards,
Frank