infix orelse
Documentation for infix orelse
assembled from the following types:
language documentation Operators
From Operators
(Operators) infix orelse
The orelse
operator is similar to infix //
, except with looser precedence and $_
aliasing.
Returns the first defined argument, or else the last argument. Last argument is returned as-is, without being checked for definedness at all. Short-circuits. The result of the left side is bound to $_
for the right side, or passed as an argument if the right side is a Callable
, whose count must be 0
or 1
.
This operator is useful for handling Failures returned by routines since the expected value is usually defined and Failure never is:
sub meowssub meows-processor1 # return handled Failuresub meows-processor2 # return re-armed Failuresub meows-processor3say ", " # OUTPUT: «Failure, True»given meows-processor1;say ", " # OUTPUT: «Failure, False»given meows-processor2;meows-processor3; # OUTPUT: «something's wrong»meows-processor3; # OUTPUT: «🐱»