Use a "real" hash, instead and you're fine.I beg to differ. Using a 'real' hash subjects you to some of the same problems you face when using symbolic references. Biggest problem: making typos.
Using hash keys as variable names is only marginally better than using symbolic references. (The advantage mainly being you won't accidentely overwrite important package variables - which in this case, given there are no non-user variables starting with 'use', isn't a serious risk). You still got to be careful to be "fine".use warnings; no strict 'refs'; my $point1 = 'valpt'; @{"use_$point1"} = ("foo", "bar"); ... my $var = 'valpt'; # Oops, typo. push @{"use_$var"}, "baz"; # Silently does the wrong thing. use strict 'refs'; my $point1 = 'valpt'; my %use; @{$use{$point1}} = ("foo", "bar"); ... my $var = 'valpt'; # Oops, typo. push @{$use{$var}}, "baz"; # Silently does the wrong thing.
In reply to Re^2: Using variables in array names
by Anonymous Monk
in thread Using variables in array names
by Lhamo_rin
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |