in reply to Dynamically naming and creating hashes
What you're talking about is called "symbolic references", and there's lots of literature explaining why it's generally a bad idea.
In your case, I would recommend the following alternative:
my( %testA, %testB, %testC ); my @hashrefs = \( %testA, %testB, %testC ); my $i = 0; foreach ( @hashrefs ) { $_->{'key'} = $i; }
In other words, you create the hashes with the names you want,
as normal.
Then, whenever you need to iterate over all of them (which seems
to be your motivation here), you iterate over a list of references
to the hashes.
In the example above, I created an array to hold the list of
hash references, in case you need the list multiple times.
If you only need it once, you could foreach over the
list of hash refs directly.
|
|---|