Try Tie::Hash::Sorted.
#!perl use strict; use warnings; use diagnostics; use Tie::Hash::Sorted; use Data::Dumper::Concise; use constant KANRI_01_0 => 0x00000001; # TBC use constant KANRI_01_1 => 0x00000002; # TBC use constant KANRI_02_0 => 0x00000004; # TBC use constant KANRI_02_1 => 0x00000008; # TBC use constant KANRI_03_0 => 0x00000010; # TBC use constant KANRI_04_1 => 0x00000020; # TBC use constant KANRI_04_2 => 0x00000040; # TBC use constant KANRI_04_3 => 0x00000080; # TBC use constant KANRI_04_4 => 0x00000100; # TBC use constant KANRI_05_1 => 0x00000200; # TBC use constant KANRI_05_2 => 0x00000400; # TBC use constant KANRI_06_1 => 0x00000800; # TBC use constant KANRI_07_1 => 0x00001000; # TBC use constant KANRI_07_2 => 0x00002000; # TBC use constant KANRI_07_3 => 0x00004000; # TBC use constant KANRI_07_4 => 0x00008000; # TBC use constant KANRI_07_5 => 0x00010000; # TBC use constant KANRI_08_1 => 0x00020000; # TBC my %menu = ( Outer1 => { O1Inne1 => KANRI_04_1, O1Inne2 => KANRI_04_2, O1Inne3 => KANRI_04_3, O1Inne4 => KANRI_04_4, }, Outer2 => { O2Inne1 => KANRI_05_1 }, Outer3 => { O3Inne1 => KANRI_06_1 }, Outer4 => { O4Inne1 => KANRI_07_1, O4Inne2 => KANRI_07_2, O4Inne3 => KANRI_07_3, O4Inne4 => KANRI_07_4, O4Inne5 => KANRI_07_5, }, Outer5 => { O5Inne1 => KANRI_08_1 }, ); my $sort_by_numeric_value = sub { my $menu = shift; [ sort {$menu->{$a} <=> $menu->{$b}} keys %$menu ]; }; tie my %sorted_menu, 'Tie::Hash::Sorted', 'Hash' => \ %menu, 'Sort_Routine' => $sort_by_numeric_value; for my $key ( keys %sorted_menu ) { warn Dumper( $key, $sorted_menu{$key}); }
Update: Here's a prettier-print:
#!perl use strict; use warnings; use diagnostics; use Tie::Hash::Sorted; use YAML; use YAML::Dumper; use constant KANRI_01_0 => 0x00000001; # TBC use constant KANRI_01_1 => 0x00000002; # TBC use constant KANRI_02_0 => 0x00000004; # TBC use constant KANRI_02_1 => 0x00000008; # TBC use constant KANRI_03_0 => 0x00000010; # TBC use constant KANRI_04_1 => 0x00000020; # TBC use constant KANRI_04_2 => 0x00000040; # TBC use constant KANRI_04_3 => 0x00000080; # TBC use constant KANRI_04_4 => 0x00000100; # TBC use constant KANRI_05_1 => 0x00000200; # TBC use constant KANRI_05_2 => 0x00000400; # TBC use constant KANRI_06_1 => 0x00000800; # TBC use constant KANRI_07_1 => 0x00001000; # TBC use constant KANRI_07_2 => 0x00002000; # TBC use constant KANRI_07_3 => 0x00004000; # TBC use constant KANRI_07_4 => 0x00008000; # TBC use constant KANRI_07_5 => 0x00010000; # TBC use constant KANRI_08_1 => 0x00020000; # TBC my %menu = ( Outer1 => { O1Inne1 => KANRI_04_1, O1Inne2 => KANRI_04_2, O1Inne3 => KANRI_04_3, O1Inne4 => KANRI_04_4, }, Outer2 => { O2Inne1 => KANRI_05_1 }, Outer3 => { O3Inne1 => KANRI_06_1 }, Outer4 => { O4Inne1 => KANRI_07_1, O4Inne2 => KANRI_07_2, O4Inne3 => KANRI_07_3, O4Inne4 => KANRI_07_4, O4Inne5 => KANRI_07_5, }, Outer5 => { O5Inne1 => KANRI_08_1 }, ); my $sort_by_numeric_value = sub { my $menu = shift; [ sort {$menu->{$a} <=> $menu->{$b}} keys %$menu ]; }; my $dumper = YAML::Dumper->new; $dumper->indent_width(1); tie my %sorted_menu, 'Tie::Hash::Sorted', 'Hash' => \ %menu, 'Sort_Routine' => $sort_by_numeric_value; for my $key ( keys %sorted_menu ) { print $dumper->dump( {ascending_values => [$key, $sorted_menu{$key}]}); }

In reply to Re: Problem with printing a Hash of Hashes in order by Khen1950fx
in thread Problem with printing a Hash of Hashes in order by KyussRyn

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.