I was thinking of basically the same thing, but with fewer square brackets thanks to some help from List::MoreUtils::natatime():

>perl -wMstrict -le "use List::MoreUtils qw(natatime); ;; my @menuStruct = ( o1 => [ o1_i1 => 0x11, o1_i2 => 0x12, o1_i3 => 0x13, o1_i4 => 0x14, ], o2 => [ o2_i1 => 0x21 ], o3 => [ o3_i1 => 0x31 ], o4 => [ o4_i1 => 0x41, o4_i2 => 0x42, o4_i3 => 0x43, ], o5 => [ o5_i1 => 0x51 ], ); ;; my $o_iter = natatime 2, @menuStruct; while (my ($ok, $ov) = $o_iter->()) { print qq{$ok}; my $i_iter = natatime 2, @$ov; while (my ($ik, $iv) = $i_iter->()) { printf qq{ $ik = %x \n}, $iv; } } " o1 o1_i1 = 11 o1_i2 = 12 o1_i3 = 13 o1_i4 = 14 o2 o2_i1 = 21 o3 o3_i1 = 31 o4 o4_i1 = 41 o4_i2 = 42 o4_i3 = 43 o5 o5_i1 = 51

I think either of these approaches could be made recursive.


In reply to Re^2: Problem with printing a Hash of Hashes in order by AnomalousMonk
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.