我如何通过Perl中的键排序散列哈希? [英] How can I sort a hash of hashes by key in Perl?
本文介绍了我如何通过Perl中的键排序散列哈希?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想排序一个实际上具有散列值的散列值。例如:
I want to sort a hash which actually has a hash as a value. For instance:
my %hash1=(
field1=>"",
field2=>"",
count=>0,
);
my %hash2;
$hash2{"asd"}={%hash1};
我将大量散列插入到%hash2
用不同的计数值%hash2
。
and I inserted lots of hashes to %hash2
with different count values of %hash2
.
如何排序%hash1 根据计数值
hash1
?
有没有办法做到这一点没有手动执行quicksort,例如使用Perl的排序功能?
Is there a way of doing this without implementing quicksort manually, for instance with the sort function of Perl?
推荐答案
my @hash1s = sort {$a->{count} <=> $b->{count}} values %hash2;
这篇关于我如何通过Perl中的键排序散列哈希?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文