in reply to How can I use the value of a scalar as the name of an array variable?
Here's how the data structure looks:
my %foods = ( fruit => [ "apples", "oranges" ], dairy => [ "eggs", "milk" ], meat => [ "sausage", "bacon" ] );
my %foods; while (<DATA>) { chomp; my( $category, $item ) = split /\t/; push @{$foods{$category}} ,$item; } for my $category ( keys %foods ) { print "$category : \n"; for my $item ( @{$foods{$category}} ) { print "\t$item\n"; } print "\n"; }
|
|---|