in reply to Meaning of //

It's the only reason I switched my more complex software to 5.10 from 5.8 minimum requirement. It alleviates doing stuff like:

sub func { my ($thing) = @_; $thing = defined $thing ? $thing : 'non-thing'; # or if (defined $thing){ $thing = $thing; } else { $thing = 'non-thing'; } }

Much cleaner to use the previously-mentioned defined-or:

sub func { my ($thing) = @_; $thing //= 'non-thing'; }

That might not look like much of a difference, but add some complexity and other rules surrounding incoming variables and you can significantly reduce the keystrokes, code complexity and most important, readability, especially if in loop-type scenarios.

Replies are listed 'Best First'.
Re^2: Meaning of //
by AnomalousMonk (Archbishop) on Oct 17, 2019 at 21:30 UTC
    ... cleaner ...

    Cleaner when used to do something reasonable as in your examples, but I hope hanspr never actually saw some of the examples given in the OP. As pointed out by pryrt,
        return 1 unless ($flag // 0);
    is exactly equivalent to
        return 1 unless $flag;
    (except more confusing), and  ... if $HAS_FOCUS // ''; likewise.


    Give a man a fish:  <%-{-{-{-<