I find this very inventive. So you know about hashes, you use a hash with the $category being the key yet you insist on using symbolic references? If you already have the hash, why don't you store the array there?
No variables springing into existence and overwriting other stuff willy-nilly, smaller memory footprint and quicker execution.use strict; use Data::Dumper; open (FOOD, "<", "food.txt") or die "Can't open food.txt: $^E"; my %categories; while (<FOOD>) { chomp; my ($category, $item) = split(/\s+/); push(@{$categories{$category}}, $item); } print ">$_<\n",Dumper($categories{$_}) for keys %categories; close FOOD;
Symbolic references are (almost) never the right solution. And you do not need to worry why I said almost for a few more years. Believe me!
In reply to Re: Answer: Can I determine if the value of a variable is the same as an arrays name?
by Jenda
in thread How can I use the value of a scalar as the name of an array variable?
by atch
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |