Skip Menu |
 

Preferred bug tracker

Please visit the preferred bug tracker to report your issue.

This queue is for tickets about the Perl-Critic CPAN distribution.

Report information
The Basics
Id: 75794
Status: open
Priority: 0/
Queue: Perl-Critic

People
Owner: Nobody in particular
Requestors: EDAVIS [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: Wishlist
Broken in: 1.117
Fixed in: (no value)



Subject: Suggested policy: /r flag on substitutions
Download (untitled) / with headers
text/plain 321b
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.
Subject: Re: [rt.cpan.org #75794] Suggested policy: /r flag on substitutions
Date: Thu, 15 Mar 2012 10:22:50 -0700
To: bug-Perl-Critic [...] rt.cpan.org
From: Jeffrey Thalhammer <jeff [...] imaginative-software.com>
Download (untitled) / with headers
text/plain 886b
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
Download (untitled) / with headers
text/plain 188b
I didn't mean a blanket policy of requiring /r on all substitutions, but rather one that looks for the particular construct (my $new = $old) =~ s/a/b/; and suggests using /r instead.


This service is sponsored and maintained by Best Practical Solutions and runs on Perl.org infrastructure.

Please report any issues with rt.cpan.org to rt-cpan-admin@bestpractical.com.