Assigning a hash to a hash

Right now I have two hashes. I want to assign one entire hash to an id in a second hash. However, I am having trouble assigning that hash into the other hash.

Can you assign a hash into another hash by just saying:

$nodes{$id}=%nodeHash;

Right now this doesn't work because when I say:

print Dumper(\%nodes);

I get this as a result:

$VAR1 = {
      'c2' => '4/8',
      'c1' => {}
    };

Sorry if this doesn't totally make sense, I am not a very experienced programmer so a hash of hashes is pretty complex.

Answers


Aggregates only store scalars. So use the ref operator to take a ref to the hash:

$nodes{$id} = \%node_hash;

or, sometimes slightly more safely, allocating a new one and copying the old one into it, then returning the new reference:

$nodes{$id} = { %node_hash };

A hash value must be a scalar, so you need to assign a hash reference:

$nodes{$id} = \%nodeHash;

You can't use a hash as the value, but you can use a reference to the hash; $nodes{$id} = \%nodeHash;


Need Your Help

Dockerize ASP Classic on IIS

docker asp-classic iis-7 docker-for-windows docker-desktop

Microsoft has been investing in running docker on windows with Docker Desktop for Windows. Is it possible to run a legacy ASP Classic application on IIS through Docker? How?