Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: "cleaning out" object data

by merlyn (Sage)
on May 20, 2005 at 12:12 UTC ( [id://458926]=note: print w/replies, xml ) Need Help??


in reply to "cleaning out" object data

Are you sure you're ready for "object oriented programming"? In all the years I've done OOP (25 years now), I've never wanted to "clean out all the data without deleting the object itself". Maybe if you state what your real problem is, we can reply with a more in-band way of accomplishing this.

I know that if I saw code like your delete, I'd pull one of those Scooby-Do scrunchy-face "HunH?" expressions. So, even if this accomplishes what you want in the short-term, you're destroying your long term maintainability. Perl code already gets a bad slap too often for that—no point in increasing that by going down the path you've started to choose.

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

Replies are listed 'Best First'.
Re^2: "cleaning out" object data
by Forsaken (Friar) on May 20, 2005 at 13:21 UTC
    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...

      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...

A reply falls below the community's threshold of quality. You may see it by logging in.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://458926]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (3)
As of 2024-04-19 22:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found