πŸ“˜ Prefix operator ~ in Perl 6

πŸ“˜ Prefix operator ~ in Raku

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


~ casts an object to a string. Note that we are now talking about the prefix or a unary operator. If the tilde is used as an infix (see later in this chapter about what infixes are), it works as a string concatenating operator, but it still deals with strings.

my Str $a = ~42;
say $a.WHAT; # (Str)

In some cases, the string context can be created implicitly, for example, when you interpolate a variable inside the double quotes.

Leave a Reply

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

Retype the CAPTCHA code from the image
Change the CAPTCHA codeSpeak the CAPTCHA code