in reply to Re: Can I determine if the value of a variable is the same as an arrays name?
in thread How can I use the value of a scalar as the name of an array variable?

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?

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;
No variables springing into existence and overwriting other stuff willy-nilly, smaller memory footprint and quicker execution.

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!

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