And should be (warnings would have complained about it):my %aMenu = { label => " A", MenuItems => [ @MenuItems ] };
my %aMenu = ( label => " A", MenuItems => [ @MenuItems ] );
or, if you don't know the A, B, C menus ahead of time, just make them on the fly as needed:# if @MenuItems actually has something it it, then MenuItems => [@M +enuItems] is fine # but for simplicity i just made it MenuItems => [] my %menus = ( a => { label => " A", MenuItems => [] }, b => { label => " B", MenuItems => [] }, c => { label => " C", MenuItems => [] }, ); #OR: my %menus = map { lc($_) => {label => " $_", MenuItems => +[]} } 'A' .. 'C'; # then: foreach my $app (map {lc $_} @sorted_applications) { push @{ $menus{$app}->{MenuItems} }, $app; }
my %menus; foreach my $app (map {lc $_} @sorted_applications) { $menus{$app} ||= { label => " ".uc($app), MenuItems => [] }; push @{ $menus{$app}->{MenuItems} }, $app; }
In reply to Re: Hashes of Arrays
by davidrw
in thread Hashes of Arrays
by plmc
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |