Re: [BEGINNER]Storable::dclone question

From: Jim Gibson (jgibson_at_mail.arc.nasa.gov)
Date: 03/26/05

  • Next message: andy.t.chou_at_gmail.com: "passing perl variable to output html file"
    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 =---


  • Next message: andy.t.chou_at_gmail.com: "passing perl variable to output html file"

    Relevant Pages

    • Re: to dispose or not ?
      ... If I use GC.KeepAlive(obj) where I would have used obj = nothing what is the cost vs the risk of not ... As a general rule, if you aren't using a finalizer or COM interop, ... setting the reference to nothing reduces the reference count to ... TheGC has a KeepAlive method MSDN explains: ...
      (microsoft.public.dotnet.languages.vb)
    • Re: Problem with reference counting
      ... creates it, it stores an uncounted reference to the object, using its key. ... Private Sub Class_Initialize ... ' get a long pointer to the item ... Dim Obj As Object ...
      (microsoft.public.vb.general.discussion)
    • Re: Problem with reference counting
      ... > creates it, it stores an uncounted reference to the object, using its> key. ... Private Sub Class_Initialize ... ' get a long pointer to the item ... Dim Obj As Object ...
      (microsoft.public.vb.general.discussion)
    • Re: Please Explain where will the struct be stored if it is declared inside the Class
      ... There are two reasons why you couldn't just grab a reference to the int ... g and stuff that reference into "obj" and call it a day. ... on the heap also allocates other stuff that goes along with it. ... The whole point of having private members like g (well, ...
      (microsoft.public.dotnet.languages.csharp)
    • Re: Determine if an item in a collection has changed - correction
      ... If lPtr <= 0 Then Exit Function ... Dim obj As Object ... > Yes, callbacks is an option. ... which by necessity holds a reference to each of its children (via ...
      (microsoft.public.vb.general.discussion)