非批,语法糖- my %hash = (0=>1, 1=>5, 4=>0, 6=>0, 8=>0, 10=>1, 12=>5, 13=>1);
- my @idx = sort { $hash{$a} <=> $hash{$b} || $a <=> $b } ( keys %hash );
- grep { printf "hash[%2d] = %d\n", $_, $hash{$_} } @idx;
复制代码
- hash[ 4] = 0
- hash[ 6] = 0
- hash[ 8] = 0
- hash[ 0] = 1
- hash[10] = 1
- hash[13] = 1
- hash[ 1] = 5
- hash[12] = 5
复制代码
|