postfix --

Documentation for postfix --, assembled from the following types:

language documentation Operators

From Operators

(Operators) postfix --

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

Decrements its argument by one, and returns the original value.

my $x = 3;
say $x--;   # OUTPUT: «3␤» 
say $x;     # OUTPUT: «2␤» 

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

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␤» 

Decrement on Str will decrement the number part of a string and assign the resulting string to the container. A is rw-container is required. Crossing 0 is prohibited and throws X::AdHoc.

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