Documentation for control flow return-rw

Documentation for control flow return-rw, assembled from the following types:

language documentation Control Flow

From Control Flow

(Control Flow) control flow return-rw

The sub return will return values, not containers. Those are immutable and will lead to runtime errors when attempted to be mutated.

sub s(){ my $a = 41return $a };
say ++s();
CATCH { default { say .^name''.Str } };
# OUTPUT: «X::Multi::NoMatch.new(dispatcher … 

To return a mutable container, use return-rw.

sub s(){ my $a = 41return-rw $a };
say ++s();
# OUTPUT: «42␤» 

The same rules as for return regarding phasers and control exceptions apply.