📘 Shortcut operator && in Perl 6

📘 Shortcut operator && in Raku

N. B. Perl 6 has been renamed to Raku. Click to read more.

&& returns the first of the operands, which, after being converted to a Boolean value, becomes False. If none are False, then the last element is returned. Please note that the result is not a Boolean value but the value of one of the operands (unless they are Boolean already).

say 10 && 0; # 0
say 0 && 10; # 0 
say 12 && 3.14 && "" && "abc"; # empty string

The operator stops its work as soon as the acceptable value has been found. The values of the rest of the operands will not be calculated. That is why the operator belongs to the group of shortcut operators.

Leave a Reply