mellin has asked for the wisdom of the Perl Monks concerning the following question:
In one of my scripts it would be very convenient to create and name hashes dynamically. I can go around this with creating hash of hashes, but if i'd like to stick with only one hash and it's key/values, how should i do this?
In the code below i'm trying to illustrate the idea.
my @hashNames = qw(testA testB testC); my $i = 0; foreach (@hashNames) { %{$_}{'key'} = $i; }
I'm trying to create a hashes like below with the example above
%testA = ( key => '0' );
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Dynamically naming and creating hashes
by jdporter (Paladin) on Apr 11, 2006 at 16:09 UTC | |
|
Re: Dynamically naming and creating hashes
by xdg (Monsignor) on Apr 11, 2006 at 18:19 UTC | |
|
Re: Dynamically naming and creating hashes
by tinita (Parson) on Apr 11, 2006 at 18:19 UTC | |
|
Re: Dynamically naming and creating hashes
by codeacrobat (Chaplain) on Apr 11, 2006 at 16:59 UTC | |
|
Re: Dynamically naming and creating hashes
by Anonymous Monk on Apr 11, 2006 at 16:30 UTC |