in reply to Something like c++'s static?
UPDATE:use strict; my @foo; push @foo, Foo->new() for (0..4); package Foo; { my $count = 0; sub get_count { return $count } sub inc_count { return ++$count } } sub new { my $class = shift; $class->inc_count(); print STDERR 'there are ', $class->get_count(), " instances\n"; my $self = { bar => 42 }; return bless $self, $class; }
The methods get_count() and inc_count() are still accessible to the client in my code, by the way. That is not necessarily a good thing ...print $Foo::count, "\n";
jeffa
L-LL-L--L-LL-L--L-LL-L-- -R--R-RR-R--R-RR-R--R-RR B--B--B--B--B--B--B--B-- H---H---H---H---H---H--- (the triplet paradiddle with high-hat)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: (jeffa) Re: Something like c++'s static?
by perrin (Chancellor) on Aug 02, 2002 at 17:43 UTC | |
|
Re: (jeffa) Re: Something like c++'s static?
by mp (Deacon) on Aug 02, 2002 at 19:47 UTC |