perl value排序

这么简单的东西,长时间不用还是忘了,记录下,方便以后查找。

#!/usr/perl/bin

use strict;  
use Data::Dumper;  
my %h=(  
  "Alex"=>24,  
  "Sam"=>25,  
  "Bob"=>30,  
  "Andy"=>11,  
  "Wills"=>35,  
  "Mary"=>16,  
  "Helen"=>24  
);  
print(Dumper(/%h)); # output original hash  
my @keys = sort { $h{$b} <=> $h{$a} } keys %h; #sort the hash table  
for (@keys){print "$_ -> $h{$_}/n"} 

你可能感兴趣的:(perl value排序)