On Mar 15, 2012, at 10:10 AM, EDAVIS via RT wrote:
Show quoted text> The old Perl idiom to perform an s/// substitution saving the result in
> a new variable was:
>
> (my $new = $old) =~ s/a/b/;
>
> Perl 5.14 introduced the cleaner alternative:
>
> my $new = ($old =~ s/a/b/r);
>
> If 5.14 or later is declared, Perl::Critic should have a policy that
> suggests replacing the old form with the new.
I think we can write a policy that specifically detects the older idiom. But I'm not convinced it is reasonable to have a blanket policy to mandate /r on all substitutions. Sometimes you don't want the side effect, sometimes you do...
s/foo/bar/ for @list;
One school of thought (that I happen to follow) is to eschew side effects...
my @new_list = map { s/foo/bar/r } @list;
So requiring /r might still be a good thing, but I think the rationale needs to be hashed out more.
-Jeff