I'm a bit confused on perl hashes.
I know that you can create a hash by calling:
my %hashTable;
$hashTable("Key") = "Value"
later on, if you want to retrieve the value, you can do
print $hashTable("Key")
However, I'm confused on this for loop
foreach (keys %{$hashTable{"key"}})
{
print $_
}
without the %{$hashTable{"key"}}, it looks that it is going to print out each of the keys, but what happens if you do a % in front of a hash table?
I tried to test out this function, by giving it a key called "key", it would give me an error: can't use string ("key") as a hash reference. Is there something to do with multi-dimensional hash tables?
hashTablecontained itself, as values, hashs. So$hashTable{"key"}would return a hash. - AntonHhashTable, with the key"key", that the value is itself a hash (you can mix what the value contains, whether a scalar, array or hash). And the linekeys %{$hashTable{"key"}}returns the keys from that value hash. - AntonHperldsc- Perl Data Structures Cookbook for more information on such structures. - Miller