atch has asked for the wisdom of the Perl Monks concerning the following question:
Suppose we have a tab-separated data file like this:
And we have this program:fruit apples fruit oranges fruit bananas meat sausages dairy eggs dairy milk meat bacon
The idea is to push the item into the array whose name is the same as the value in $category. I don't want to have an if else statement for each array.my( @fruit, @meat, @dairy ); while (<>) # input redirected appropriately { chomp; my( $category, $item ) = split /\t/; push ???$category???, $item; # what now?? }
Originally posted as a Categorized Question.
Back to
Seekers of Perl Wisdom