in reply to syntax for hashes with variable in name
Don't go that road. Please. Done that, been there. It leads to unwanted things, in the widest sense of "unwanted". Really!
Symbolic reference (where the name of the hash/array/scalar is in a variable name) can always be made strict and safer by embedding it inside a hash:
my $hash_name = "platform_$site"; %$hash_name = ( key => $value ); : my $value = ${$hash_name}{key};
=>
my %global_hash; my $hash_name = "platform_$site"; $global_hash{$hash_name} = { key => $value }; : my $value = $global_hash{$hash_name}{key};
Or - even better - go with jethro's suggestion to use multidimensional data structures.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: syntax for hashes with variable in name
by aquarium (Curate) on Nov 23, 2010 at 02:44 UTC |