📘 Prefix operator ++ in Perl 6

📘 Prefix operator ++ in Raku

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

++ 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"; 

say $f; # file002.txt 

say $f; # file003.txt

Leave a Reply