bobg2011 has asked for the wisdom of the Perl Monks concerning the following question:

Hi Guys,

I'm still a learning perl, and I was hoping someone would be kind enough to help me.

I am trying to assign a Hash value to a Hash of Hashes. So for example something like this. Which doesn't work.

my %HOH = {}; %hash1 = ( key1 => 'value1', key2 => 'value2', key3 => 'value3', ); %hash2 = ( key1 => 'value1', key2 => 'value2', key3 => 'value3', ); $HOH{'1'} = %hash1; $HOH{'2'} = %hash2;

Any help with this is very much appreciated.

Replies are listed 'Best First'.
Re: Adding Hash to Hash of Hash?
by Anonymous Monk on Dec 21, 2011 at 11:15 UTC
Re: Adding Hash to Hash of Hash?
by Anonymous Monk on Dec 21, 2011 at 14:49 UTC

    Also, be sure to include: use strict; use warnings; in your code.   This will cause Perl to enforce many useful strictures that will help you to detect many common mistakes “at compile time.”

    References are one of the key concepts in Perl (and many other languages).   You can put “anything” in “one spot” (or, if you like, “in several spots at once”) because what you are actually doing is putting “a reference to” whatever-it-is in that spot.   This enables you to create arbitrary data structures out of just a handful of simple building-blocks and to manage them efficiently.   But, yes, you need to thoughtfully and carefully read the various perldoc articles on the subject:   once you get a firm grasp of the concepts, it will become second nature.