plmc has asked for the wisdom of the Perl Monks concerning the following question:
I used the following to populate each MenuItem array.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 ] };
And the following to print the first element.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; ...
I would like to avoid using $aMenu in the printing and use something like, $abc_menu instead of hard coding $aMenu, $bMenu such as;print " @{$aMenu{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.foreach my $abc_menu (@menu_bar_names) { print " @{$abc_menu{MenuItems}}[0]\n"; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Hashes of Arrays
by davidrw (Prior) on Jun 05, 2006 at 20:43 UTC | |
|
Re: Hashes of Arrays
by philcrow (Priest) on Jun 05, 2006 at 20:36 UTC | |
|
Re: Hashes of Arrays
by GrandFather (Saint) on Jun 05, 2006 at 20:55 UTC | |
by plmc (Acolyte) on Jun 06, 2006 at 13:11 UTC |