[MacPerl] persistent local variable
[email protected] (Louis Pouzin) Sun, 13 Mar 2005 02:27:19 +0100 (MET)
| Newsgroups | perl.macperl |
|---|---|
| Message-ID | <[email protected]> |
Just what I needed. Merci Bart.
- -
On Sat, 12 Mar 2005 10:27:49 +0100, Bart Lateur wrote:
>Use a lexical, in a block around your subs you want to allow access.
Like this:
{
my $count;
sub get {
return ++$count;
}
sub clear {
undef $count;
}
}
$\ = "\n";
for (1..5) {
print get;
}
clear();
for (1..3) {
print get;
}
Result:
1
2
3
4
5
1
2
3
- -