>>>>> "JG" == Jim Green <[email protected]> writes:
JG> i have a question for the following perl code, by changing the value
JG> in %h3, the script also changes the value for %h4, I vaguely
JG> understand it is because %h3's key is reference to %h2, %h2's key is
JG> reference to %h1,
JG> so by changing value in %h3, the script also changes the value for %h4,
JG> I was wondering if there is a way to address this problem, I don't
JG> want by changing $h3{k3}{k2}{k1} = "v2", %h4 also got changed.
JG> Thank you list for any pointers, I am absolute newbie and I am learning..
JG> my %h1 = ( k1 => "v1" );
JG> my %h2 = ( k2 => \%h1 );
JG> my %h3 = ( k3 => \%h2 );
JG> my %h4 = %h3;
that is just copying the reference to %h2 into %h4 so of course they
refer to the same lower hash. you want a deep copy so you can isolate
things. you can do that with Data::Dumper/eval and there are other
modules which support this (Storable i think for one).
uri
--
Uri Guttman ------ [email protected] -------- http://www.sysarch.com --
----- Perl Code Review , Architecture, Development, Training, Support ------
--------- Gourmet Hot Cocoa Mix ---- http://bestfriendscocoa.com ---------
--
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
http://learn.perl.org/