September 2017
Beginner
402 pages
9h 52m
English
The assignment meta-operator takes the op= form, where op is one of the operators available in Perl 6.
For example, take the infix + operator. In its default form, it takes two operands and adds them up, returning the result.
my $a = 10;my $b = 20;my $c = $a + $b;say $c; # 30
In this example, the $c variable receives the sum of $a and $b, which stays unchanged.
In the meta-operator form, the += operator changes the left operand and stores the result in it, as shown here:
my $d = 10;my $e = 20;$e += $d;say $e; # 30
The $a += $b expression is always equivalent to the following $a = $a + $b form.
The assignment meta-operator works with many other infix operators. Consider the
following example:
my $x = pi;$x *= 2/3; ...
Read now
Unlock full access