|Don't ask to ask, just ask|
Deep Copying of Nested Data-Structuresby stefan k (Curate)
|on Sep 01, 2003 at 09:46 UTC||Need Help??|
stefan k has asked for the wisdom of the Perl Monks concerning the following question:
Dear Monks, having coded a lot in C++ in the last few months I'm now a bit paranoid and probably to C++-ish in my thinking. Therefore I'd be more than happy to be enlightened on the following problem by a real Perl guru :-)
I've created a class (let's call it CLASS) that has a nested data structure like this:
Then I want to copy it like this:
And next to that I need to change a value in the arrays of $c2. Since I have the instance variables as lots of references changing a value in $c2 always changes the corresponding value in $c1.
I had hoped that Perl would clean that mess for me but I doesn't seem so.
Now, do I need to write some sort of copy constructur (*yuck* even the word makes me shudder) and if so how do I do this or is there any other way of nicely solving this mess in a Perl-ish manner?
Thanks in advance for any pointers what to read or hints or code or other forms of enlightenment.