sort函数用来对数组进行排序。用法如下:
#按字符排序 @articles = sort @files;
#按字符排序,显式说明 @articles = sort {$a cmp $b} @files;
#按字符排序,忽略大小写 @articles = sort {uc($a) cmp uc($b)} @files;
#按字符排序,逆序 @articles = sort {$b cmp $a} @files;
#按数字顺序排序 @articles = sort {$a <=> $b} @files;
#按数字顺序排序,逆序 @articles = sort {$b <=> $a} @files;
#按散列的值排序 @oldest = sort {$age{$b} <=> $age{$a} } keys %age;
source : http://b.zemounteragtadist.com/?p=49