SPUG: defaulting a value

David Dyck david.dyck at fluke.com
Wed Oct 29 00:32:07 CST 2003


On Tue, 28 Oct 2003 at 21:52 -0800, Michael R. Wolf <MichaelRWolf at att.net>...:

> Anyone remember the status of // as an or-ish operator? If's it's
> available pre-Perl6, then the following would be my suggestion for
> defaulting an undefined value, but preserving 0 (not necessary in this
> case, but is necessary in the general case):
>
>     $debug //= 0;


perldelta.pod from perl, v5.9.0 has:

NAME
       perldelta - what is new for perl v5.9.0

DESCRIPTION
       This document describes differences between the 5.8.0
       release and the 5.9.0 release.

 .......


  Defined-or operators
    A new operator "//" (defined-or) has been implemented. The following
    statement:

        $a // $b

    is merely equivalent to

       defined $a ? $a : $b

    and

       $c //= $d;

    can be used instead of

       $c = $d unless defined $c;

    This operator has the same precedence and associativity as "||". It has a
    low-precedence counterpart, "err", which has the same precedence and
    associativity as "or". Special care has been taken to ensure that those
    operators Do What You Mean while not breaking old code, but some edge
    cases involving the empty regular expression may now parse differently.
    See perlop for details.




More information about the spug-list mailing list