Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re: (jeffa) Re: Something like c++'s static?

by perrin (Chancellor)
on Aug 02, 2002 at 17:43 UTC ( [id://187162]=note: print w/replies, xml ) Need Help??


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; }

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://187162]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others browsing the Monastery: (9)
As of 2024-04-23 13:08 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found