I've having difficulty with a hash of arrays. I'm creating a dropdown menu system with headers a b .. z under each letter is are menuItems beginning with a b .. z. my structure looks like this;
my @menu_bar_names = qw ( aMenu bMenu ... ); my @MenuItems=""; my %aMenu = { label => "  A", MenuItems => [ @MenuItems ] }; my %bMenu = { label => "  B", MenuItems => [ @MenuItems ] }; my %cMenu = { label => "  C", MenuItems => [ @MenuItems ] };
I used the following to populate each MenuItem array.
foreach my $app (@sorted_applications) { $app = lc $app; if ( "$app" lt "b" ) { push ( @{ $aMenu{MenuItems} }, $app); next; } elsif ($app lt "c" ) { push (@{ $bMenu{MenuItems} },$app); next; ...
And the following to print the first element.
print " @{$aMenu{MenuItems}}[0]\n";
I would like to avoid using $aMenu in the printing and use something like, $abc_menu instead of hard coding $aMenu, $bMenu such as;
foreach my $abc_menu (@menu_bar_names) { print " @{$abc_menu{MenuItems}}[0]\n"; }
but I get the following error. 'Global symbol "abc_menu"; requires explicit package name at...' The error makes sense and I understand why I get it. But I haven't figured out how to get around it. I'm sure it's something simple but I've read so much I've confused myself. Thanks for taking the time to read this.

In reply to Hashes of Arrays by plmc

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.