++
ErrorsCollection

++

Synthesised documentation from language/operators language/operators

From language/operators

See Original text in context

multi sub prefix:<++>($x is rwis assoc<non>

Increments its argument by one and returns the updated value.

my $x = 3;
say ++$x;   # OUTPUT: «4␤» 
say $x;     # OUTPUT: «4␤»

It works by calling the succ method (for successor) on its argument, which gives custom types the freedom to implement their own increment semantics.

From language/operators

See Original text in context

multi sub postfix:<++>($x is rwis assoc<non>

Increments its argument by one and returns the original value.

my $x = 3;
say $x++;   # OUTPUT: «3␤» 
say $x;     # OUTPUT: «4␤»

It works by calling the succ method (for successor) on its argument, which gives custom types the freedom to implement their own increment semantics; when undefined, it sets the value to 1 and returns it.

my $x;
$x++;
say $x;     # OUTPUT: «1␤»

Note that this does not necessarily return its argument; e.g., for undefined values, it returns 0:

my $x;
say $x++;   # OUTPUT: «0␤» 
say $x;     # OUTPUT: «1␤»

Increment on Str will increment the number part of a string and assign the resulting string to the container. An is rw container is required.

my $filename = "somefile-001.txt";
say $filename++ for 1..3;
# OUTPUT: «somefile-001.txt␤somefile-002.txt␤somefile-003.txt␤»

This will act on any Unicode numeral:

my $was٧ = "ثمانية٧";
$was٧++;
say $was٧# OUTPUT: «ثمانية٨␤» 

Including, since version 6.d, Thai numerals

my $เลขไทย="๙๙";
$เลขไทย++;
say $เลขไทย# OUTPUT: «๑๐๐␤»