#! perl use strict; use warnings; package Widget { my $count = 0; sub new { my ($class, @args) = @_; my %self = @args; ++$count; return bless \%self, $class; } sub DESTROY { --$count; } sub get_count { return $count; } } package main; my $w1 = Widget->new(name => 'foo', value => 42); my $w2 = Widget->new(name => 'bar', value => 7); my $w3 = Widget->new(name => 'baz', value => 12); printf "Now there are %d Widgets\n", Widget::get_count; undef $w1; printf "Now there are %d Widgets\n", Widget::get_count; #### 15:52 >perl 856_SoPW.pl Now there are 3 Widgets Now there are 2 Widgets 15:52 >