Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re: Writing a REAL destructor

by Abigail-II (Bishop)
on Jun 05, 2002 at 15:03 UTC ( #171853=note: print w/replies, xml ) Need Help??


in reply to Re: (MeowChow) Re: Writing a REAL destructor
in thread Writing a REAL destructor

Keeping track of the number of instances can very well be done via DESTROY. I wouldn't put in a reference in the object though. Then you make the count accessable outside your class, and you probably don't want to do that.

Use something like:

package MyClass; my $count = 0; sub new { my $proto = shift; my $class = ref $proto || $proto; $count ++; my $obj = ....; bless $obj => $class; } sub DESTROY { $count --; }
And do not call DESTROY yourself. Perl will do that for you.

Abigail

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://171853]
help
Chatterbox?
and the leaves swirl about...

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (5)
As of 2017-12-17 04:28 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What programming language do you hate the most?




















    Results (462 votes). Check out past polls.

    Notices?