需要遍历的哈希名字是 %hash
按键遍历
for my $key (keys%hash){
}
按键排序遍历
for my $key (sort keys%hash){
}
按值数字遍历
从小到大
for my $key ( sort { $hash{$a} <=> $hash{$b} } keys %hash ) {
}
从大到小
for my $key ( sort { $hash{$b} <=> $hash{$a} } keys %hash ) {
}
按值的ASCII码排序
for my $key ( sort { $hash{$a} cmp $hash{$b} } keys %hash ) {
}