How to sort perl hash on values and order the keys correspondingly (in two arrays maybe)?

前端 未结 4 1634
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-08 15:03

In Perl, I want to sort the keys of a hash by value, numerically:

{
  five => 5
  ten => 10
  one => 1
  four => 4
}

producing

4条回答
  •  死守一世寂寞
    2020-12-08 15:37

    Please see the Perl FAQ entry titled "How do I sort a hash (optionally by value instead of key)"

    http://perldoc.perl.org/perlfaq4.html#How-do-I-sort-a-hash-%28optionally-by-value-instead-of-key%29?

    You can also use perldoc -q to search the FAQ locally on your machine, as in perldoc -q sort, which is how I found your answer.

提交回复
热议问题