f***y 发帖数: 98 | 1 I have a hash like this:
%h = (
org, 51,
com, 7,
gov, 55,
net, 2,
biz, 5
);
How do I print it out with its value numerically sorted? It would look like:
gov 55
org 51
com 7
biz 5
net 2
Any suggestion would be appreciated. Thanks a lot! | b***t 发帖数: 1104 | 2 foreach $k (sort keys %hash) {
print "$k => $hash{$k}\n";
}
【在 f***y 的大作中提到】 : I have a hash like this: : %h = ( : org, 51, : com, 7, : gov, 55, : net, 2, : biz, 5 : ); : How do I print it out with its value numerically sorted? It would look like: : gov 55
| t****t 发帖数: 6806 | 3 peng! besides, the solution is not correct...
【在 b***t 的大作中提到】 : foreach $k (sort keys %hash) { : print "$k => $hash{$k}\n"; : }
| b***t 发帖数: 1104 | 4 foreach $value (sort { $h{$a} <=> $h{$b} } keys %h) {
print "$value => $h{$value}\n";
}
【在 t****t 的大作中提到】 : peng! besides, the solution is not correct...
|
|