Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perlsub: mention when //= and ||= in signatures were added #22919

Merged
merged 1 commit into from
Jan 19, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading