- 论坛徽章:
- 0
|
我在网上找了一些代码,都大差不差的
但是排出来的序似乎都不大对劲啊
#!/usr/bin/perl
##auth Allen Zhang
##date 2007-12-06
use Data::Dumper;
%hash = ( 'MG816W10' => 126.5,
'A00098' => 39.585,
'RP10874' => 31.624,
'A00160' => 65.975,
'MG420W15' => 126.5,
'MG816W15' => 126.5,
'MM0904' => 42.56,
'A00296' => 51.1,
'MG420W10' => 126.5
);
# original hash:
print Dumper(\%hash);
# mothod two:
foreach my $key ( sort { $hash{$a} cmp $hash{$b} } keys %hash ) {
printf("%s\t\t%d\n", $value, $hash{$key});
}
# mothod two:
@sorted = map { { ($_ => $hash{$_}) } } sort { $hash{$a} cmp $hash{$b}or $a cmp $b} keys %hash;
print Dumper(\@sorted);
exit; |
排出来的结果都是这样的:
126
126
126
126
31
39
42
51
65
65到了最后?
问题在哪里呢? |
|