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'm afraid that version will silently discard everything. @{$category} will never be true, because all of your pre-declared arrays start with zero elements.
You could do something like this:
But really, why would you want to? I think it's much simpler to restrict the categories if you use a hash of lists.@fruit = (undef); @meat = (undef); @dairy = (undef); while (<FOOD>) { chomp; ($category, $item) = split(' ', $_); push(@{$category}, $item) if (defined @{$category}); } shift @fruit; shift @meat; shift @dairy;
|
|---|