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?

Quote:
    push(@{$category}, $item) if (@{$category});
...
    Note that this version would only push items with pre-declared categories, the rest would be silently discarded

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:

@fruit = (undef); @meat = (undef); @dairy = (undef); while (<FOOD>) { chomp; ($category, $item) = split(' ', $_); push(@{$category}, $item) if (defined @{$category}); } shift @fruit; shift @meat; shift @dairy;
But really, why would you want to? I think it's much simpler to restrict the categories if you use a hash of lists.