📘 Method postfix operator .= in Perl 6

📘 Method postfix operator .= in Raku

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


.=method is a mutating call of the method on an object. The call $x.=method does the same as the more verbose assignment $x = $x.method.

In the following example, the $o container initially holds an object of the C class, but after $o.=m(), the value will be replaced with an instance of the D class.

class D { } 

class C {
    method m() {
        return D.new;
    }
}

my $o = C.new;
say $o.WHAT;  # (C) 

$o.=m();
say $o.WHAT;  # (D)

Leave a Reply