Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: Object::Clone a simple class providing a cloning method

by dws (Chancellor)
on Nov 19, 2001 at 02:43 UTC ( #126181=note: print w/replies, xml ) Need Help??


in reply to Object::Clone a simple class providing a cloning method

How to correctly clone an object is a problem that people run into again and again and again, and the answer each time is that no general solution is possible.

Without semantic knowledge, it is not always possible to know in advance whether a shallow copy of the object is sufficient, whether a deep copy is required, or whether a correct copy requires something in between the two.

A shallow copy of an object treats instance data as static data that can be simply copied into a new instance. For some objects, including those based on arrays or hashes where all values are simple scalars, this works. But as soon as a value is a reference to another object, you have to make a choice between simply copying the reference (i.e., making a shallow copy), or recursively cloning the referred-to object (i.e., making a deep copy). In a moderately sophisticated system, you're liable to run into objects that require some combination of shallow and deep copying in order to be successfully cloned.

  • Comment on Re: Object::Clone a simple class providing a cloning method

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://126181]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (5)
As of 2021-12-01 16:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    R or B?



    Results (13 votes). Check out past polls.

    Notices?