in reply to How can I use the value of a scalar as the name of an array variable?

You could try something like this...

@fruit = (); @meat = (); @dairy = (); open (FOOD, "./food.txt"); while(<FOOD>) { chomp; ($category,$item) = split(/\s+/,$_); push(@{"$category"},$item); }


But of course, that all assumes you trust your input.

cephas

Originally posted as a Categorized Answer.

  • Comment on Re: Can I determine if the value of a variable is the same as an arrays name?
  • Download Code