πŸ“˜ 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";Β 

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

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

Leave a Reply

Your email address will not be published. Required fields are marked *

Retype the CAPTCHA code from the image
Change the CAPTCHA codeSpeak the CAPTCHA code