in reply to (jeffa) Re: Something like c++'s static?
in thread Something like c++'s static?

Damian's example is fine if you need to hide all variables behind methods, but the use of closures often confuses newbies. The simple answer to this question is to just use a (package-scoped) global:
use strict; my @foo; push @foo, Foo->new() for (0..4); package Foo; use vars qw($count); sub new { my $class = shift; $count++; print STDERR 'there are ', $count, " instances\n"; my $self = { bar => 42 }; return bless $self, $class; }