http://www.perlmonks.org?node_id=288102

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:

my $self = { nest => [ [ [ 1, 2, 3 ], [ 4, 5, 6 ], ], ], more => [ 3, 2, 1 ] };
Then I want to copy it like this:
my $c1 = new CLASS; my $c2 = $c1;
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.

Regards... Stefan
you begin bashing the string with a +42 regexp of confusion