in reply to Re: dynamically creating the name of a hash key-name
in thread dynamically creating the name of a hash key-name
One way to do pretty much what you're asking for relates to a reply above: what you can do is have an array of anonymous hashes, of the form:
my @array_of_hashes = ( {hashkey1=>$hashval1, hashkey2=>$hashval2}, {hashkey1=>$hashval1, hashkey2=>$hashval2} ... );
You access the individual hashes with syntax like:
# to modify what's in the second hash $array_of_hashes[1]->{hashkey1} = "ay carumba!"; # $array_of_hashes[1]{hashkey1} would also work! # to iterate over the hashes foreach my $hashref (@array_of_hashes) { # $hashref is now a reference to one of the hashes in @array _of_hashe +s # we need to de-reference to go through the keys of the hash foreach (keys %$hashref) { print "$_ => ", $hashref->{$_}, "\n"; } }
HTH
Philosophy can be made out of anything -- or less
|
|---|