πŸ“˜ Prefix operator + in Perl 6

+ 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

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s