"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. > This is the way: > > { > my $cnt=0; > sub Inc { > return $cnt++; > } > } Yes, but I'm trying here to explain the function of 'our'. This is the simplest example of it, where there's only one 'us' :) Yes folks. Declaring a subroutine within a block of its own may be ugly, but it's the recognised way of implementing persistent variables. 'our' doesn't protect you variables as completely as it might. Cheers, Rob -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]