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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |