boom has asked for the wisdom of the Perl Monks concerning the following question:

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};

and I inserted lots of hashes to %hash2 with different count values of %hash2. How can I sort the %hash1 according to a count value of hash1? Is there a way of doing this without implementing quicksort manually, for instance with the sort function of Perl?

Replies are listed 'Best First'.
Re: How can I sort a hash of hashes by key in Perl?
by Corion (Patriarch) on Apr 18, 2009 at 13:09 UTC
Re: How can I sort a hash of hashes by key in Perl?
by CountZero (Bishop) on Apr 18, 2009 at 18:03 UTC
    And don't forget to have a look at the Schwartzian_Transform!

    CountZero

    A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James

Re: How can I sort a hash of hashes by key in Perl?
by ww (Archbishop) on May 30, 2010 at 23:56 UTC
    See the answer to the identical question, posted at stackoverflow just 5 days before the parent node appeared.

    Think of the "p" word, which might be "pattern" (see this poster's other questions), but isn't.