Search notes:

Perl operator // (slash slash)

The slash slash operator in perl returns the left side value if it is defined, otherwise it returns the right side value.
This differs from the || operator in that the || operator checks for truth rather than definendness.
$x //= 'value' assigns 'value' to $x unless $x is defined.
The slash slash operator comes in handy, for example, when handling null values with one of the DBD modules.
use warnings;
use strict;
use feature 'say';

my $p;
my $q  = "foo";
my $r  = "";
my $t  = "0";


say $p // "bar"; # bar
say $q // "bar"; # foo
say $r // "bar"; #
say $t // "bar"; # 0

say "----------";

$p //= "V";
$q //= "V";
$r //= "V";
$t //= "V";

say $p; # v
say $q; # foo
say $r; #
say $t; # 0
Github repository about-perl, path: /operators/slash_slash.pl

See also

Perl operators

Index