Raku Books / Perl 6 at a Glance / Operators / Prefixes
!, not
! is the Boolean negation operator.
say !True; # False
say !(1 == 2); # TrueThe not operator does the same but has lower
precedence.
say not False; # True↻ Runs in Rakudo; the in-browser engine (Raku++) doesn’t support this program yet — see the expected output above.
CodeBlockPlaceholder3raku my Str $price = ‘4’ ~ ‘2’; my Int $amount = +$price;
say $amount; # 42 say $price.Numeric; # 42 CodeBlockPlaceholder4
We will see one of the important use cases of the unary plus in
Chapter 6: +$/. That construction converts an object of the
Match class that contains information about the matched
part of the regular expression into a number.
- is a unary minus, which changes the sign of its
operand. Because this operator silently calls the Numeric
method, it can also cast the context, as it does the unary plus
operator.
my Str $price = '4' ~ '2';
say -$price; # -42