如何简单的按照hash中的值的sort顺序输出key和value对 - Perl -

2025-04-25 23:56:24
推荐回答(1个)
回答1:

[ol][*]use 5.014;[*]my %hash = ([*]? ? \'Jodan\' => \'1.98\',[*]? ? \'Wade\'??=> \'1.93\',[*]? ? \'James\' => \'2.08\',[*]? ? \'T_mac\' => \'2.03\',[*]? ? \'Yao\'? ?=> \'2.29\',[*]? ? \'Paul\'??=> \'1.83\',[*]? ? \'Kobe\'??=> \'1.98\',[*]? ? \'AI\'? ? => \'1.83\',[*]? ? \'KG\'? ? => \'2.10\',[*]);[*]say for map { \"$_ => $hash{$_}\" } sort { $hash{$b} $hash{$a} } keys %hash;[/ol][ol][*]Yao => 2.29[*]KG => 2.10[*]James => 2.08[*]T_mac => 2.03[*]Jodan => 1.98[*]Kobe => 1.98[*]Wade => 1.93[*]AI => 1.83[*]Paul => 1.83[/ol]