As I want to continue to use Keys for this, even though I think that the nested array structure will work just as well, I came up with the solution below using the suggestions from this thread here.
#!c:\Perl\bin\perl use warnings; use strict; use diagnostics; use Tie::IxHash; use constant KANRI_01_0 => 0x00000001; use constant KANRI_01_1 => 0x00000002; use constant KANRI_02_0 => 0x00000004; use constant KANRI_02_1 => 0x00000008; use constant KANRI_03_0 => 0x00000010; use constant KANRI_04_1 => 0x00000020; use constant KANRI_04_2 => 0x00000040; use constant KANRI_04_3 => 0x00000080; use constant KANRI_04_4 => 0x00000100; use constant KANRI_05_1 => 0x00000200; use constant KANRI_05_2 => 0x00000400; use constant KANRI_06_1 => 0x00000800; use constant KANRI_07_1 => 0x00001000; use constant KANRI_07_2 => 0x00002000; use constant KANRI_07_3 => 0x00004000; use constant KANRI_07_4 => 0x00008000; use constant KANRI_07_5 => 0x00010000; use constant KANRI_08_1 => 0x00020000; sub ordered_hash_ref { tie my %hash, 'Tie::IxHash', @_; return \%hash; } tie my %menuHash, 'Tie::IxHash', Outer1 => ordered_hash_ref( O1Inne +1 => KANRI_04_1, O1Inne2 => KANRI_04_2, O1Inne3 => KANRI_04_3, O1Inne4 => KANRI_04_4, ) , Outer2 => ordered_hash_ref( O2Inne1 => KANRI_05_1 ), Outer3 => ordered_hash_ref( O3Inne1 => KANRI_06_1 ), Outer4 => ordered_hash_ref( O4Inne1 => KANRI_07_1, O4Inne2 => KANRI_07_2, O4Inne3 => KANRI_07_3, O4Inne4 => KANRI_07_4, O4Inne5 => KANRI_07_5, ), Outer5 => ordered_hash_ref( O5Inne1 => KANRI_08_1 ), ; for my $mainMenuItem ( keys %menuHash ) { print $mainMenuItem."\n"; for my $subMenuItem ( keys %{ $menuHash{$mainMenuItem} } ) { print "$subMenuItem = $menuHash{$mainMenuItem}{$subMenuIte +m} "; } print "\n"; }
This provided the following output.
After reading the Tie::IxHash help, then doing an online search using the keyword "preserving", helped me find other resources. I hope that this post helps others and thank you to Granfather and Toolic for your replies to my request for help.Outer1 O1Inne1 = 32 O1Inne2 = 64 O1Inne3 = 128 O1Inne4 = 256 Outer2 O2Inne1 = 512 Outer3 O3Inne1 = 2048 Outer4 O4Inne1 = 4096 O4Inne2 = 8192 O4Inne3 = 16384 O4Inne4 = 32768 +O4Inne5 = 65536 Outer5 O5Inne1 = 131072
In reply to Re: Problem with printing a Hash of Hashes in order
by KyussRyn
in thread Problem with printing a Hash of Hashes in order
by KyussRyn
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |