๐Ÿ“˜ 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

Your email address will not be published. Required fields are marked *