Meta-operators in Perl 6
So far, we have covered many of the operators that operate on regular operands—values, variables, objects, and so on. In Perl 6, there are operators of another kind—operators that operate over operators. These operators are called meta-operators. We will examine them in the following sections. With some exceptions, every meta-operator can take any regular operator to create a new operation that follows certain rules. Meta-operators also work with user-defined operators, which we will discuss later in this chapter, in the User-defined operators section.
Assignment meta-operator
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 ...