📘 Prefix operator ++ in Perl 6

++ is a prefix operator of increment. First, an increment is done, and then a new value is returned.

my $x = 41;
say ++$x; # 42

The increment operation is not limited to working only with numbers. It can also handle strings.

my $a = 'a';
say ++$a; # b

A practical example is to increment filenames containing numbers. The file extension will survive, and only the numerical part will be incremented.

my $f = "file001.txt"; 

++$f;
say $f; # file002.txt 

++$f;
say $f; # file003.txt

📘 Prefix operator ^ in Perl 6

^ is a range-creating operator or the so-called upto operator. It creates a range (which is an object of the Range type) from 0 up to the given value (not including it).

.print for ^5; # 01234

This code is equivalent to the following, where both ends of the range are explicitly specified:

.print for 0..4; # 01234

📘 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()