I am having trouble printing out a submenu from a hash which also contains the main menu as in the code below.
my %menus = ( '1' => { 'ITEM' => 'List and Kill UDT* processes by u +ser', 'ACTION' => $RunCMD->('ListKillProc') }, '2' => { 'ITEM' => 'List and Kill Print Jobs', 'ACTION' => $PrintSubmenu->('2'), 'SUBMENU' => { '1' => ( 'ITEM' => 'Show all P +rinters', 'ACTION' => $RunCMD->(' +showprintersall') ), '2' => ( 'ITEM' => 'Show user +print jobs', 'ACTION' => $RunCMD->(' +showprintersuser') ), '3' => ( 'ITEM' => 'Show singl +e printer', 'ACTION' => $RunCMD->(' +showprinter') ), '4' => ( 'ITEM' => 'Kill a pri +nt job', 'ACTION' => $RunCMD->(' +killprint') ) } }, '3' => { 'ITEM' => 'Manage user accounts', 'ACTION' => $PrintSubmenu->('3'), 'SUBMENU' => { '1' => ( 'ITEM' => 'Unlock us +er account', 'ACTION' => $RunCMD->( +'unlockuser') ), '2' => ( 'ITEM' => 'Change ac +count password', 'ACTION' => $RunCMD->( +'changepass') ) } }, '4' => { 'ITEM' => 'Run App', 'ACTION' => $RunCMD->('APP') }, '5' => { 'ITEM' => 'quit', 'ACTION' => $RunCMD->('quit') } ); .. SNIP .. my $print_menu = \&print_main_menu; my $PrintSubmenu = \&print_sub_menu; #$print_menu->(); $PrintSubmenu->('3'); ################### sub print_main_menu ################### { print "$_\t", $menu->{$_}->{'ITEM'}, "\n" for ( sort keys %menus ); } ################## sub print_sub_menu ################## { my $MenuItem = shift; #print "$_\t", $menu->{$MenuItem}->{'SUBMENU'}->{$_}->{'ITEM'}, "\ +n" # for ( sort keys %{ $menus{$_} } ); for my $Items ( sort keys %{ $menus{$MenuItem}{'SUBMENU'} } ) { print "$menus{$MenuItem}{'SUBMENU'}{$Items}\n"; } #print Dumper %{ $menu->{$MenuItem}->{'SUBMENU'} }; }
I am able to print the main menu OK, but I am having trouble getting the submenu to print as so:
1 ITEM1 2 ITEM2 3 ITEM3
Thanks in advance for any suggestions

Ted
--
"That which we persist in doing becomes easier, not that the task itself has become easier, but that our ability to perform it has improved."
  --Ralph Waldo Emerson

In reply to Printing a subset of a data structure by tcf03

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.