Slash Boxes
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

Ovid (2709)

  (email not shown publicly)
AOL IM: ovidperl (Add Buddy, Send Message)

Stuff with the Perl Foundation. A couple of patches in the Perl core. A few CPAN modules. That about sums it up.

Journal of Ovid (2709)

Friday November 16, 2007
07:39 AM

Boolean operators should always have a negated version?

[ #34908 ]

So if I do this:

$value ||= $default;

I can also do this:

$value &&= munge($value);

However, what's the negated // operator?

$value //= $default;

I'm sure there must be something there, but I'm missing it.

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
More | Login | Reply
Loading... please wait.
  • But that said, the operator that parallels &&= in this case can be defined by:

    $value = defined($value) ? $other_value : undef;

    but I'm not sure what it would be good for.
    • Reminds me of this:


      Use Alternate Value. If parameter is null or unset, nothing is substituted, otherwise the expansion of word is substituted.

      That’s from man bash [] under “Parameter Expansion”. It comes in handy when you want to decide whether to pass a switch to a program based on the presence of some flag variable.

    • It's useful if you want to munge a value if it's defined. I've found it useful when doing something like this:

      $message &&= $cgi->p($message);

      In other words, if there is no message, don't stick in extraneous paragraph tags in the HTML. I'm sure there are plenty of other cases where you might want to take an extra action if a value is defined.