in reply to Copying Objects
That way, the code will "do the right thing" depending on the object type as well. For a simple shallow copy of a hash object, this will work:my $b = $a; # copy the reference, to pass a single object around my $c = $a->copy; # create a copy, to have a new object like the old o +ne
sub copy { my $self = shift; bless { %$self }, ref $self; }
-- Randal L. Schwartz, Perl hacker
Be sure to read my standard disclaimer if this is a reply.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: •Re: Copying Objects
by lapointd (Initiate) on Jul 17, 2003 at 12:19 UTC | |
by merlyn (Sage) on Jul 17, 2003 at 15:09 UTC |