Secondly, your %newhash should not be empty after the copy operation, but be advised that it will contain references to the ORIGINAL second level hashes from the first assignment. Example:
use strict; use Data::Dumper; my %first; $first{'foo'}{'bar'} = 1; $first{'foo'}{'baz'} = 2; $first{'bah'}{'oof'} = 3; print "First hash:\n"; print Dumper \%first; my %second = %first; print "\nSecond hash\n"; print Dumper \%second; print "\nFirst nested hash address: $first{'foo'}\n"; print "Second nexted hash address: $second{'foo'}\n";
output:
First hash: $VAR1 = { 'bah' => { 'oof' => 3 }, 'foo' => { 'baz' => 2, 'bar' => 1 } }; Second hash $VAR1 = { 'bah' => { 'oof' => 3 }, 'foo' => { 'baz' => 2, 'bar' => 1 } }; First nested hash address: HASH(0x804ee40) Second nexted hash address: HASH(0x804ee40)
In reply to Re: Copying a hash to another hash problem
by mfriedman
in thread Copying a hash to another hash problem
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |