in reply to Copying a hash to another hash problem
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)
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Re: Copying a hash to another hash problem
by Anonymous Monk on Oct 22, 2002 at 14:42 UTC | |
by demerphq (Chancellor) on Oct 22, 2002 at 16:11 UTC | |
by Anonymous Monk on Oct 23, 2002 at 07:41 UTC |