P
Praveen Kallakuri
hello,
i am having a problem with stable sort.
************************************************************
use strict;
use sort 'stable';
.....
....
foreach my $key (sort { $a <=> $b && $sums{$b} <=> $sums{$a} } keys
%sums) {
printf TMPFILE "%d\n",$key;
}
print OUT "\n";
....
....
************************************************************
sums is a hash with the following key-value pairs:
2 3
3 4
4 2
5 4
6 3
i want the hash sorted by the values, but the sequence of keys to be
preserved when possible. so, what i am expecting is something like 3 5 2 6
4. but what i get is below:
3
5
6
2
4
why can't i get the 6 after 2 even though i am using stable sort? thanks
for any suggestions. btw i am using perl 5.8 on a debian-woody.
thanks
praveen
i am having a problem with stable sort.
************************************************************
use strict;
use sort 'stable';
.....
....
foreach my $key (sort { $a <=> $b && $sums{$b} <=> $sums{$a} } keys
%sums) {
printf TMPFILE "%d\n",$key;
}
print OUT "\n";
....
....
************************************************************
sums is a hash with the following key-value pairs:
2 3
3 4
4 2
5 4
6 3
i want the hash sorted by the values, but the sequence of keys to be
preserved when possible. so, what i am expecting is something like 3 5 2 6
4. but what i get is below:
3
5
6
2
4
why can't i get the 6 after 2 even though i am using stable sort? thanks
for any suggestions. btw i am using perl 5.8 on a debian-woody.
thanks
praveen