Assigning a hash to another hash key

Hello,

I have a hash in hsh. I need to assign it to another hash globalHsh. I think the below statement does not work

    $globalHsh\{$id\} = %hsh;

What is the right way to assign it?

Thanks

$globalHsh{$id} = %hsh;

If you want to copy the hash, then it is.,

         %globalHsh = %hsh;

If you want to store the reference of the hash hsh as value to the globalhash's key, then

         $globalHsh{$id} = \%hsh;

I did the second option but I am still not able to access the internal hash key?

$globalHash{$id}{"class"}

My internal hash has a class key. Is the above the right way to access a hash within a hash?

Yeah that is the right way to access... If you are manipulating the internal hash correctly.

my %hsh = (
    class => 'value of class',
    dummy => 'testing',
);

my $id = '10';
my %globalHash;

$globalHash{$id} = \%hsh;

print $globalHash{$id}{'class'};
$ perl file.pl
value of class