Re: [BEGINNER]Storable::dclone question
From: Jim Gibson (jgibson_at_mail.arc.nasa.gov)
Date: 03/26/05
- Previous message: soup_or_power_at_yahoo.com: "[BEGINNER]Storable::dclone question"
- In reply to: soup_or_power_at_yahoo.com: "[BEGINNER]Storable::dclone question"
- Next in thread: soup_or_power_at_yahoo.com: "Re: [BEGINNER]Storable::dclone question"
- Reply: soup_or_power_at_yahoo.com: "Re: [BEGINNER]Storable::dclone question"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Fri, 25 Mar 2005 18:13:25 -0800
In article <1111790795.584878.284830@l41g2000cwc.googlegroups.com>,
<soup_or_power@yahoo.com> wrote:
> Can someone explain this code especially what it is doing with
> Storable::dclone? Thanks in advance
>
> sub new {
> my ($self, $hash) = @_;
>
> # ------------------------------------------------------
> # Create new hash ref/obj ref (Copy Constructor)
> # ------------------------------------------------------
>
> my $type = ref($self) || $self;
> my $obj = ( ref $self ) ? &Storable::dclone( $self ) : { };
If $self is a reference (to an object instance in this case), then
dclone($self) makes a deep-clone copy of that object and assigns it (a
new reference) to $obj, which then is blessed as a new object.
If $self is not a reference, it is a package, and $obj becomes a new,
empty object (reference to empty hash).
> my $new = bless $obj, $type;
>
> # ------------------------------------------------------
> # Initialize properties (copy $hash into $new)
> # ------------------------------------------------------
>
> if ($hash && ref $hash) {
> while ( my ($key, $value) = each %$hash ) {
> $new->{$key} = $value if ! ref $value;
> }
> }
>
> return $new;
> }
>
FYI: this newsgroup is defunct; please do not start threads here. Try
comp.lang.perl.misc in the future.
----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! >100,000 Newsgroups
---= East/West-Coast Server Farms - Total Privacy via Encryption =---
- Previous message: soup_or_power_at_yahoo.com: "[BEGINNER]Storable::dclone question"
- In reply to: soup_or_power_at_yahoo.com: "[BEGINNER]Storable::dclone question"
- Next in thread: soup_or_power_at_yahoo.com: "Re: [BEGINNER]Storable::dclone question"
- Reply: soup_or_power_at_yahoo.com: "Re: [BEGINNER]Storable::dclone question"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|