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