📘 Method postfix operator . in Perl 6

There are a few syntactical elements in Perl 6, which start with a dot. These operators might look like a postfix operator, but they all are the forms of the calling a method on an object. Unlike Perl 5, the dot operator does not do any string concatenation.

.method calls a method on a variable. This works with both real objects and with those variables, which are not instances of any class, for example, built-in types like integers.

say "0.0".Numeric; # 0
say 42.Bool;       # True 

class C {
    method m() {say "m()"}
my $c = C.new;
$c.m(); # m()

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