On Mon, Feb 03, 2003 at 11:57:29AM +1100, simran wrote:
> On Mon, 2003-02-03 at 09:37, Rob Dixon wrote:
> > "John W. Krahn" <[EMAIL PROTECTED]> wrote in message
> > [EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
> > > [EMAIL PROTECTED] wrote:
> > > >
> > > > $var|=10; # like that if u want to set the variable to a default
> > value--
> > > >           # if the $var is not defined it assigns a value of 10  to
> > it.
> > >
> > > You need to use the ||= operator not the |= operator for that.
> > 
> > ... and it will change $var to ten if it is already set to zero.
>
> perhaps such a statement would suit:
> 
> $var = defined $var ? $var : 10;

It probably sits better with something like:

  $var = 10 unless defined $var;

But 5.10 will (probably) introducde the // operator which will allow you
to say:

  $var //= 10;

just like Perl 6 (will).

-- 
Paul Johnson - [EMAIL PROTECTED]
http://www.pjcj.net

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

Reply via email to