David wrote:
> 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];

That should, of course, be

    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.

You miss my point by taking the second half of my post out
of context. I was comparing the problem of cloning an
object with the simpler one of copying an array reference
without simply duplicating the refrence.

Rob




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

Reply via email to