in reply to Interpolation in variable names
You don't want to use a variable as a variable name. Dominus has said why much better than I can. Most likely, you want to use a hash to store the information about fruits:
my %fruits = { orange => { name => 'Malus', size => 123 }, apple => { name => 'Citrus sinensis', size => 10 }, };
You can then access your data as
my $fruit = 'orange'; print $fruits{ $fruit }->{name}, "\n"; print $fruits{ $fruit }->{size};
Also see tye's References Quick Reference for how to use references.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Interpolation in variable names
by ddc_nh (Initiate) on Mar 16, 2010 at 14:29 UTC | |
by Hue-Bond (Priest) on Mar 16, 2010 at 15:49 UTC |