From: "Rob Dixon" <[EMAIL PROTECTED]>
> "Jenda Krynicky" <[EMAIL PROTECTED]> wrote in message
> 3E2E9EDB.5722.62EB5D@localhost">news:3E2E9EDB.5722.62EB5D@localhost...
> > From: "Rob Dixon" <[EMAIL PROTECTED]>
> > > There was an example in there that demonstrated
> > > using 'our' to implement a C-like 'static' variable.
> >
> > Well ... if you mean something like
> >
> > int Inc() {
> > static int cnt;
> > return cnt++;
> > }
> >
> > then our() is not the right way to do that in Perl. the our() only
> > allows you to use the short name instead of $the::complete::one.
> 
> It also protects your variable from modification by code which hasn't
> declared it.

#!perl
use strict;

sub Inc {
        our $inc;
        return $inc++;
}

print Inc(),"\n";
print Inc(),"\n";
$main::inc = 100;
print Inc(),"\n";
__END__

I would not call this protection.

Jenda

===== [EMAIL PROTECTED] === http://Jenda.Krynicky.cz =====
When it comes to wine, women and song, wizards are allowed 
to get drunk and croon as much as they like.
        -- Terry Pratchett in Sourcery


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to