in reply to How can I use the value of a scalar as the name of an array variable?
Prints:my %Categories; while (<>) { my( $category, $item ) = split /\t/, $_, 2; push @{$Categories{$category}}, $item; } print "$_\n" for sort @{$Categories{'dairy'}};
eggs milk
If you must have the arrays as separate variables (not just as values in the %Categories hash), you could define
%Categories = ( fruit => \@fruit, meat => \@meat, dairy => \@dairy, );
|
|---|