You don't exactly tell us what you're expecting for output... nor is your example values enough to indicate certain behaviours even if you were to give us the output for the above HoH.

I'm going to take a quick guess:

#!/usr/bin/perl use strict; use warnings; my %HoH = ( www => { wwe => 1, wte => 2, wee => 0} ); for my $outter (sort keys %HoH) { for my $inner (sort { $HoH{$outter}{$a} <=> $HoH{$outter}{$b} } ke +ys %{$HoH{$outter}}) { print "${outter}::$inner = $HoH{$outter}{$inner}\n"; } }
producing:
$ perl ./x.pl www::wee = 0 www::wwe = 1 www::wte = 2
Probably not entirely what you want, but I can't be sure.

Update: Probably closer to what you want:

#!/usr/bin/perl use strict; use warnings; my %HoH = ( www => { wwe => 11, wte => 21, wee => 0}, zzz => { zze => 15 }, ); my @keys = sort { $HoH{$a->[0]}{$a->[1]} <=> $HoH{$b->[0]}{$b->[1]} } map { my $outter = $_; map { [ $outter, $_ ] } keys %{$HoH{$outter}}; } keys %HoH; for (@keys) { print( (join '::', @$_), ' = ', $HoH{$_->[0]}{$_->[1]}, "\n"); }
which produces:
$ perl ./x.pl www::wee = 0 www::wwe = 11 zzz::zze = 15 www::wte = 21
I'm sure one of the other monks has a more generic solution here (probably either TheDamian or Merlyn) for handling arbitrary depths...


In reply to Re: how to sort HoH according to value by Tanktalus
in thread how to sort HoH according to value by sovixi

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.