Rob Dixon wrote:

> 
> you couldn't get a new object by simply writing:
> 
>     my $object2 = $object;
> 
> as what you would have is simply a second handle
> to the same object, and all changes to one would
> be echoed in the other. You would have to do:
> 
>     my $object2 = clone ($object);
> 
>     sub clone {
>         my $original = shift;
>         my @newdata = @$original;
>         return [EMAIL PROTECTED];
>     }
> 

this will not clone the object for you. the function only makes a copy of 
the referenced data the object represent and then return another ref back 
to the caller.

at it's min. you need:

sub clone{
        my $obj = shift;
        return bless [EMAIL PROTECTED] => ref $obj;
}

or the object will be lost. this is still, by far, not perfect. it only does 
a shadow copy, if $obj contains reference to other objects, the clone will 
not be distinct from the orginal object.

david

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to