On Tue, 2002-04-16 at 15:51, Elias Assmann wrote:
> On 16 Apr 2002, Chas Owens wrote:
> > sub has_a_static_var {
> >     #declare a "static" variable
> >     my $static if 0;
> >
> >     if (defined $static) { $static++   }
> >     else                 { $static = 0 }
> >
> >     #do stuff
> > }
> 
> May I ask why you do this if-else thing here? It seems superflous to
> me.
> 
>       Elias
> 
> -- 
> "There are people who don't like capitalism, and there are people who don't like PCs,
> but there's no one who likes the PC who doesn't like Microsoft."
>  -- Bill Gates

The idea behind this sub is that $static gets incremented each time you
call the subroutine.  If that is not what you want then yes, the if-else
is not needed.  In that case you would want to say something like:

sub sub1 {
        my $static if 0;
        #this line is not necessary unless you need
        #a default value for you static variable
        $static = "DEFAULT" unless defined $static;

        #do something
}
 
-- 
Today is Sweetmorn the 33rd day of Discord in the YOLD 3168
Umlaut Zebra über alles!

Missile Address: 33:48:3.521N  84:23:34.786W


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

Reply via email to