Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
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?
[Corion]: Wheee! The videos of the German Perl Workshop 2018 are online :)

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (8)
As of 2018-07-23 15:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    It has been suggested to rename Perl 6 in order to boost its marketing potential. Which name would you prefer?















    Results (471 votes). Check out past polls.

    Notices?