M3 sub r - markov2/perl5-Mail-Box GitHub Wiki

Substitute attribute 'r'

The 'r' attribute to substitute got introduced in 5.12, and simplifies some code beautifully; it does not modify the left-hand value of the =~ but returns the result.

my $a = func();  $a =~ s/x/y/;            my $a = func() =~ s/x/y/r;
(my $a = $b) =~ s/x/y/;                   my $a = $b =~ s/x/y/r;

The latter reads better: was "first copy the source then modify", becomes "modify the source, and store the result".

⚠️ **GitHub.com Fallback** ⚠️