Skip to content

Commit

Permalink
perlsub: mention when //= and ||= in signatures were added
Browse files Browse the repository at this point in the history
  • Loading branch information
Grinnz authored and khwilliamson committed Jan 19, 2025
1 parent 0a14b9f commit 54be012
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions pod/perlsub.pod
Original file line number Diff line number Diff line change
Expand Up @@ -401,19 +401,19 @@ one parameter vary according to the earlier parameters. For example,
print "$first_name $surname is known as \"$nickname\"";
}

A default value expression can also be written using the C<//=> operator,
where it will be evaluated and used if the caller omitted a value or the
value provided was C<undef>.
Since Perl 5.38, a default value expression can also be written using the
C<//=> operator, where it will be evaluated and used if the caller omitted
a value or the value provided was C<undef>.

sub foo ($name //= "world") {
print "Hello, $name";
}

foo(undef); # will print "Hello, world"

Similarly, the C<||=> operator can be used to provide a default
expression to be used whenever the caller provided a false value (and
remember that a missing or C<undef> value are also false).
Similarly since Perl 5.38, the C<||=> operator can be used to provide a
default expression to be used whenever the caller provided a false value
(and remember that a missing or C<undef> value are also false).

sub foo ($x ||= 10) {
return 5 + $x;
Expand Down

0 comments on commit 54be012

Please sign in to comment.