Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re: Hash in a Hash Issue

by nevdka (Pilgrim)
on Jul 23, 2013 at 23:49 UTC ( [id://1045969]=note: print w/replies, xml ) Need Help??


in reply to Hash in a Hash Issue

It looks like you want to use an anonymous hash:

use strict; use warnings; my %hash = ( 'key 1' => { 'innerhash1 key 1' => 'some data', 'innerhash1 key 2' => 'some more data', }, 'key 2' => { 'innerhash2 key 1' => 'even more data', 'innerhash2 key 2' => 'a bit more data', }, ); foreach my $key (keys %hash) { foreach my $inner_key ( keys %{$hash{$key}} ) { print "$inner_key $hash{$key}->{$inner_key}\n"; } }

$hash{'key 1'} contains a reference to the inner hash, but the inner hash itself is no longer named. You could rework the rest of your code to put data directly into there, and not have to worry about overwriting the data you've put in another inner hash.

If you want to seek more wisdom on your own, search for 'hash of hashes' or HoH if you're on a Perl site (like this one).

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (4)
As of 2024-04-19 14:28 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found