Hi

There must be a better way, but this the best idea I could come up quickly from the top of my mind, and it works:

use strict; use warnings; my @array; my $VAR1 = { '1.2.3.4' => { '27029' => 5, '20617' => 1 }, '1.2.3.5' => { '51509' => 1, '17427' => 1, '63961' => 7, '22331' => 1, '20780' => 7 }, '1.2.3.6' => { '1500' => 3 }, + }; for my $var1 (keys %$VAR1) { push @array, [$var1, $_, $$VAR1{$var1}{$_}] for keys %{$$VAR1{$var +1}}; } print map {$_->[0], "\t", $_->[1], "\t", $_->[2], "times \n"} sort {$a +->[2] <=> $b->[2]} @array;
Output:
1.2.3.5 51509 1times 1.2.3.5 17427 1times 1.2.3.5 22331 1times 1.2.3.4 20617 1times 1.2.3.6 1500 3times 1.2.3.4 27029 5times 1.2.3.5 63961 7times 1.2.3.5 20780 7times

Update This is strange, there was no answer when I posted my answer, and now it appears that two monks actually posted before me. I do not understand this and would probably have not posted the above if I has seen the prevoous answers.


In reply to Re: Sorting a HoH by values of the nested hashes by Laurent_R
in thread Sorting a HoH by values of the nested hashes by reisinge

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.