My Big Problem is that I must copy an object to do a backtracking method
(I am going to develop a sudoku solver).
Uri Guttman schrieb:
"CF" == Christoph Friedrich <christ...@christophfriedrich.de> writes:
CF> I have searched the internet but didn't found a good answer.
CF> How do I clone a Perl Object?
CF> For example like this:
CF> $a = My::Object->new();
CF> $b = $a->clone();
the answer is you can't in the general case. only the class should be
able to clone an object as it knows the implementation. you can't just
do a deep copy if it is implemented with inside out objects or other
stuff that won't allow external code to inspect it.
the only solutions are use a class that supports its own cloning method
or get all the data out of the object with accessor calls and construct
a new object from that.
and i bet you really don't need this but you just think you do. explain
what your bigger problem is and with what particular classes. cloning
isn't a general need in most designs.
uri