Jenda Krynicky wrote:
> 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.

I would. I would be surprised if this was coded accidentally! This is
a valid circumvention of the access limitations, which protect
programmers from themselves but still allow access in a special
case. Non-exported module contents can also be accessed this
way, but that isn't considered a breach of security either. I would
be more unhappy if such a piece of code was forced to declare
the variable again with 'our' and thereby give unfettered access
throughout the scope.

Cheers,

Rob





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

Reply via email to