To help other beginner perl programmers, for the final use of this program, I ended up using a hash that used constants as the Keys as well.

This caused me some more stress as Constants don't really work well with what I was planning to do. How I solved this was to move the constants to a seperate file (this was going to be the original plan as I have a seperate perl module in my project that holds all of the constants).

For easy reference for programmers who are looking at using this method for making a HTML menu (or other uses here is the dummy final code I created:

#!c:\Perl\bin\perl use warnings; use strict; use diagnostics; use CGI ':standard'; use CGI::Carp qw(fatalsToBrowser); use Tie::IxHash; use CONSTANTS; tie my %menuHash, 'Tie::IxHash',CONSTANTS::TOP_MENU1_ => ordered_ha +sh_ref( CONSTANTS::TM1_SUB1_ => CONSTANTS::KANRI_SCREEN_04_1, CONSTANTS::TM1_SUB2_ => CONSTANTS::KANRI_SCREEN_04_2, CONSTANTS::TM1_SUB3_ => CONSTANTS::KANRI_SCREEN_04_3, CONSTANTS::TM1_SUB4_ => CONSTANTS::KANRI_SCREEN_04_4 ), CONSTANTS::TOP_MENU2_ => ordered_hash_ref( CONSTANTS::TM2_SUB1_ + => CONSTANTS::KANRI_SCREEN_05_1 ), CONSTANTS::TOP_MENU3_ => ordered_hash_ref( CONSTANTS::TM3_SUB1_ + => CONSTANTS::KANRI_SCREEN_06_1 ), CONSTANTS::TOP_MENU4_ => ordered_hash_ref( CONSTANTS::TM4_SUB1_ + => CONSTANTS::KANRI_SCREEN_07_1, CONSTANTS::TM4_SUB2_ => CONSTANTS::KANRI_SCREEN_07_2, CONSTANTS::TM4_SUB3_ => CONSTANTS::KANRI_SCREEN_07_3, CONSTANTS::TM4_SUB4_ => CONSTANTS::KANRI_SCREEN_07_4, CONSTANTS::TM4_SUB5_ => CONSTANTS::KANRI_SCREEN_07_5 ), CONSTANTS::TOP_MENU5_ => ordered_hash_ref( CONSTANTS::TM5_SUB1_ + => CONSTANTS::KANRI_SCREEN_08_1 ); my $cgi = new CGI; sub PrintMenu { my $upperMenu = shift; print "<hr>\n"; print $cgi->start_table( { -width => '100%', -border => 0 }); print "\n"; print '<tr align="center">'."\n"; for my $mainMenuItem ( keys %menuHash ) { print "<th>"; print $mainMenuItem; print "</th>\n"; } print "</tr>\n"; print $cgi->end_table(); print "<hr>\n"; print $cgi->start_table( { -width => '100%', -border => 0 }); print '<tr align="center">'."\n"; for my $subMenuItem ( keys %{ $menuHash{$upperMenu} } ) { print "<th>"; print $cgi->a( {-href => $menuHash{$upperMenu}{$subMenuItem +}, -target => '_self' }, "$subMenuItem" ); print "</th>\n"; } print "</tr>\n"; print $cgi->end_table(); print "\n"; print "<hr>\n"; } PrintMenu( CONSTANTS::TOP_MENU1_ );

And the code for the CONSTANTS.pm file is:

#!c:\Perl\bin\perl use warnings; use strict; package CONSTANTS; use constant { TOP_MENU1_ => 'TopMenu1', TOP_MENU2_ => 'TopMenu2', TOP_MENU3_ => 'TopMenu3', TOP_MENU4_ => 'TopMenu4', TOP_MENU5_ => 'TopMenu5', TM1_SUB1_ => 'SubMenu11', TM1_SUB2_ => 'SubMenu12', TM1_SUB3_ => 'SubMenu13', TM1_SUB4_ => 'SubMenu14', TM2_SUB1_ => 'SubMenu21', TM3_SUB1_ => 'SubMenu31', TM4_SUB1_ => 'SubMenu41', TM4_SUB2_ => 'SubMenu42', TM4_SUB3_ => 'SubMenu43', TM4_SUB4_ => 'SubMenu44', TM4_SUB5_ => 'SubMenu45', TM5_SUB1_ => 'SubMenu51', };

I hope this is helpful to people who read this with the same questions I had.


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

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.