in reply to How can I use the value of a scalar as the name of an array variable?
Note that this version would only push items with pre-declared categories, the rest would be silently discarded -- this might be the behaviour you want, it might not. Your call.my( @fruit, @meat, @dairy ); while (<>) { chomp; my( $category, $item ) = split /\t/; push @{$category}, $item if defined @$category; }
Update: fixed test per chipmunk's reply.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Answer: Can I determine if the value of a variable is the same as an arrays name?
by Fastolfe (Vicar) on Nov 30, 2000 at 20:33 UTC | |
|
Re: Answer: Can I determine if the value of a variable is the same as an arrays name?
by chipmunk (Parson) on Nov 30, 2000 at 20:52 UTC |