Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: Getting Keys From Hash In a Hash

by 2teez (Priest)
on Aug 08, 2013 at 18:38 UTC ( #1048624=note: print w/ replies, xml ) Need Help??


in reply to Getting Keys From Hash In a Hash

Like this:

my %form; my %field = ( 'key 1' => 'value 1', 'key 2' => 'value 2', ); $form{another_hash} = \%field; for my $first_key ( keys %form ) { for my $hoh_keys ( keys %{ $form{$first_key} } ) { print $hoh_keys, $/; ## get the keys } }
You can also check perldsc. or **Specifically: Access and Printing of a HASH OF HASHES
You really can use Data::Dumper to see how the data structure looks like, then you can get at what you want.
use Data::Dumper; ... print Dumper \%form;
produces..
$VAR1 = { 'another_hash' => { 'key 2' => 'value 2', 'key 1' => 'value 1' } };
** Updates.

If you tell me, I'll forget.
If you show me, I'll remember.
if you involve me, I'll understand.
--- Author unknown to me


Comment on Re: Getting Keys From Hash In a Hash
Select or Download Code
Replies are listed 'Best First'.
Re^2: Getting Keys From Hash In a Hash
by HalNineThousand (Beadle) on Aug 08, 2013 at 19:25 UTC

    Thank you!

    My mistake was that when I used this:

    keys %{ $form{$first_key} }
    I was leaving out the $ in front of form, like this:
    keys %{ form{$first_key} }

    So I at least remembered some of what I was doing - forgot how to treat it within the brackets.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1048624]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (9)
As of 2015-07-31 06:52 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (274 votes), past polls