in reply to Re: "cleaning out" object data
in thread "cleaning out" object data

Very well, the specific application for which I need this is an object that stores information regarding an IRC connection. Channelnames, the nicks of the people on those channels, their modes, etc. etc. etc. However, should for some reason the connection fail all that info is moot and needs to disappear, and will be reassembled once the connection has been reestablished.

Remember rule one...

Replies are listed 'Best First'.
Re^3: "cleaning out" object data
by merlyn (Sage) on May 20, 2005 at 13:30 UTC
    Ok, then you don't want to completely delete your instance vars. You want to reset the values of those vars to empty:
    sub reset_me { my $self = shift; $self->{known_nicks} = {}; $self->{known_channelnames} = {}; }
    In fact, you can use that code during your initialization as well. Then when you add a new instance var, you'll have a clean place to initialize it for everyone.

    -- Randal L. Schwartz, Perl hacker
    Be sure to read my standard disclaimer if this is a reply.


    update: And as an afterthought, this will also permit your class to be reused for subclasses more directly, since you won't be accidentally clearing out variables that your subclasses need to retain.
      Sounds like an excellent approach, think I just might do it that way.

      Disclaimer 1: this was more of a "hmm, wonder how this would work, let's see if the monks know" kinda question than a real "omg, I *MUST* know this in order to be able to progress" kinda thing.
      Disclaimer 2: I'm a big boy. Although it could have been phrased differently merlyn's original questions were perfectly valid.

      Remember rule one...