📘 Prefix operator + in Perl 6

📘 Prefix operator + in Raku

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


+ is the unary plus operator, which casts its operand to the numerical context. The action is equivalent to the call of the Numeric method.

my Str $price = '4' ~ '2';
my Int $amount = +$price;

say $amount;        # 42
say $price.Numeric; # 42

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.

Leave a Reply