Can sombody explain keys to me? I get that keys %hash returns an array with the key values. But how do I use keys when I have a hash of hashes? How do I find the second set of keys? I'm very new to perl so please be simple in you responses. Thanks, guys.
A hash of hashes consists of an outer hash and many inner hashes. To get the keys of the outer hash, you would use:[tt]
@k=keys %outerhash;[/tt]
To get the keys of an inner hash, you would use:[tt]
@k=keys %{$outerhash{'innerhash'}};[/tt]
$outerhash{'innerhash'} represents the value of an element of $outerhash, but that value happens to be a hash, so you can then cast it as a hash by putting it inside %{...} and get its keys.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.