in reply to Access Complex Hash
On the other hand, if we assume that the square brackets in key3 are a typographic error, as it probably is, then the answer to the question would be straightforward, such as:
print $$hash{'key1'}{'key2'}{'key3'}; ==> will print "Hello"
If you want to iterate through the structure, you might use the keys function, and, since this function requires a hash argument, you might have to tell Perl explicitly that this is what it is, e.g. noting the underlined text below:
keys %{$$hash{'key1'}{'key2'}}
Finally, note that $$hash{'key'} is a shorthand, a favorite of mine, that also could have been written $hash->{'key'}.
Notice that in my example the hash-keys are string literals as they must be. If you had omitted the quotes, Perl would interpret them as so-called barewords, and, if you did not use use strict; use warnings;, you might not be advised of the issue. Perl might interpret them as (undefined...) variables and produce nothing useful.
Data::Dumper is always your friend.
HTH ...
Replies are listed 'Best First'. | |
---|---|
Re^2: Access Complex Hash
by perl@1983 (Sexton) on May 15, 2012 at 13:48 UTC | |
by locked_user sundialsvc4 (Abbot) on May 15, 2012 at 20:29 UTC |