There is also a good article on the topic at http://www.stonehenge.com/merlyn/UnixReview/col30.html
<snip> Now, this simple deep_copy routine will break if there are recursive data pointers (references that point to already seen data higher in the tree). For that, you might look at the dclone method of the Storable module, found in the CPAN. </snip> HTH, José. -----Original Message----- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Sent: Tuesday, July 29, 2003 11:29 PM To: [EMAIL PROTECTED] Subject: Deep Copy I am trying to make a deep copy in a complex data structure. I have a hash that has all of its values as anonymous arrays. I need to copy the entire hash as a completely separate hash so that I can manipulate the data in the copy without affecting the original data. Copying the key of the hash is easy, that is plain data. However copying the value is harder because it is the anonymous array (so whenever I try to copy the data, it always copies the reference to the array). ----------------------------------------- my $hashref; sub hashref() { return $hashref; } $hashref->{ele1} = ["val1", "val2"]; $hashref->{ele2} = ["val3", "val4"]; $hashref->{ele3} = ["val5", "val6"]; my %newhash = %$hashref; my @keys = keys(%newhash); foreach my $arraykey (@keys) { my $ref = $hashref->{$arraykey}; $newhash{$arraykey} = @$ref; } --------------------------------------------------- But then when I do: -------------------------------------------------- $newhash{ele1}->[0]="x"; $newhash{ele2}->[0]="y"; print $hashref->{ele1}->[0]; print $hashref->{ele2}->[0]; ------------------------------------------------ It changes the values in both the referenced hash and the copied hash. How do I get a real copy? TIA Brian Seel -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] **** DISCLAIMER **** "This e-mail and any attachment thereto may contain information which is confidential and/or protected by intellectual property rights and are intended for the sole use of the recipient(s) named above. Any use of the information contained herein (including, but not limited to, total or partial reproduction, communication or distribution in any form) by other persons than the designated recipient(s) is prohibited. If you have received this e-mail in error, please notify the sender either by telephone or by e-mail and delete the material from any computer". Thank you for your cooperation. For further information about Proximus mobile phone services please see our website at http://www.proximus.be or refer to any Proximus agent. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]