By your posts title, you want to print the key of the "first" entry in the referenced hash. There's really no "first", as hashes aren't stored in any particular order. But if that's really what you want, you should be able to do it like:
my ($first_key) = keys %{$samplehash{$key}}; print "\n $key = " . $first_key;
However, I think I'd simply show the hash structure by replacing the print statement with:
foreach $key (keys %samplehash) { print "\n$key = {\n"; foreach $subkey (keys %{$samplehash{$key}}) { print "\t$subkey = $samplehash{$key}{$subkey}"; } print "\n}"; }
and then adding (after the end
...roboticus
When your only tool is a hammer, all problems look like your thumb.
In reply to Re: Print the key of the first hash table in hash of hashes
by roboticus
in thread Print the key of the first hash table in hash of hashes
by sundeep
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |