in reply to Re: Using variables in array names
in thread Using variables in array names
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.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Using variables in array names
by herveus (Prior) on Aug 05, 2005 at 13:30 UTC | |
by Anonymous Monk on Aug 05, 2005 at 13:42 UTC | |
by herveus (Prior) on Aug 05, 2005 at 13:57 UTC | |
by Anonymous Monk on Aug 05, 2005 at 14:19 UTC | |
by blazar (Canon) on Aug 05, 2005 at 14:45 UTC | |
by herveus (Prior) on Aug 05, 2005 at 14:26 UTC | |
by shemp (Deacon) on Aug 05, 2005 at 17:50 UTC | |
|
Re^3: Using variables in array names
by polypompholyx (Chaplain) on Aug 05, 2005 at 12:57 UTC |