Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

How do I make a hash of hashes?

by vroom (His Eminence)
on Jan 12, 2000 at 00:35 UTC ( [id://1978]=perlquestion: print w/replies, xml ) Need Help??

vroom has asked for the wisdom of the Perl Monks concerning the following question: (data structures)

How do I make a hash of hashes?

Originally posted as a Categorized Question.

Replies are listed 'Best First'.
Re: How do I make a hash of hashes?
by blackfrier (Initiate) on Feb 02, 2000 at 17:40 UTC
    You can declare it like:
    %hash = ( arms => { biggest => 'mine', smallest => 'yours' }, feet => { biggest => 'right', smallest => 'left' }, legs => { biggest => 'theirs', smallest => 'them', muscular => 'yes' } );
Re: How do I make a hash of hashes?
by chromatic (Archbishop) on Apr 01, 2000 at 01:13 UTC
    You can also add a hash by doing something like this:
    $hash{toes} = { biggest => 'hairy troll', smallest => 'toddler', };
    (Note that the {} make a reference to an anonymous hash. See perlman:perldsc for more gritty details.)
Re: How do I make a hash of hashes?
by Doraemon (Beadle) on May 13, 2004 at 08:10 UTC
    This might interest you:
    $other_hash{key} = ''; $hash{other} = \%other_hash; $hash{other}->{key} = '1'; # ok $tmp = $hash{other}; $$tmp{key} = '2'; # use it like this # $$hash{other}{key} = '2'; # but not like this ${$hash{other}}{key} = '3'; # this is ok $hash{other}{key} = '3'; # this too, -> unneeded after { +}
Re: How do I make a hash of hashes?
by da w00t (Sexton) on Feb 23, 2000 at 01:20 UTC
    If it was declared as a named hash of multiple dimensions, you may access it like $hash{foo}->{bar}->{beer}="free";, or like this: $hash{foo}{bar}{beer}="free"; if you prefer to drop the arrows.

    If it's an anonymous hash held in a hash reference, you access it like this:

    $r_hash->{foo}{bar}{beer}= "free";
Re: How do I make a hash of hashes?
by Doraemon (Beadle) on May 13, 2004 at 08:12 UTC
    Ahh, sorry! Not 'reference to anonymous hash', but 'reference to hash'.

    Originally posted as a Categorized Answer.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (3)
As of 2024-04-21 07:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found