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:
Low/Low
Queue:

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

BugTracker
Severity:
Wishlist
Broken in:
1.117
Fixed in:
(no value)



Subject: Suggested policy: /r flag on substitutions
MIME-Version: 1.0
Content-Type: text/plain; charset="UTF-8"
X-Mailer: MIME-tools 5.427 (Entity 5.427)
Content-Disposition: inline
Content-Transfer-Encoding: binary
X-RT-Original-Encoding: utf-8
Content-Length: 321
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.
From jeff@imaginative-software.com Thu Mar 15 13: 23:01 2012
MIME-Version: 1.0 (Apple Message framework v1084)
X-Spam-Status: No, score=-1.899 tagged_above=-99.9 required=10 tests=[AWL=0.001, BAYES_00=-1.9] autolearn=ham
In-Reply-To: <rt-3.8.HEAD-10809-1331831401-11.75794-4-0@rt.cpan.org>
X-Mailer: Apple Mail (2.1084)
X-Spam-Flag: NO
References: <RT-Ticket-75794@rt.cpan.org> <rt-3.8.HEAD-10809-1331831401-11.75794-4-0@rt.cpan.org>
X-Virus-Scanned: Debian amavisd-new at bestpractical.com
Content-Type: text/plain; charset="utf-8"
Message-ID: <2CFB713A-D8C7-46A3-A21A-9BB2946BEBFA@imaginative-software.com>
X-RT-Original-Encoding: utf-8
X-Spam-Score: -1.899
Received: from localhost (localhost [127.0.0.1]) by hipster.bestpractical.com (Postfix) with ESMTP id 542AE2401BB for <cpan-bug+Perl-Critic@hipster.bestpractical.com>; Thu, 15 Mar 2012 13:23:01 -0400 (EDT)
Received: from hipster.bestpractical.com ([127.0.0.1]) by localhost (hipster.bestpractical.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id emeJ96QDdTm8 for <cpan-bug+Perl-Critic@hipster.bestpractical.com>; Thu, 15 Mar 2012 13:23:00 -0400 (EDT)
Received: from la.mx.develooper.com (x1.develooper.com [207.171.7.70]) by hipster.bestpractical.com (Postfix) with SMTP id 062362400EB for <bug-Perl-Critic@rt.cpan.org>; Thu, 15 Mar 2012 13:22:59 -0400 (EDT)
Received: (qmail 679 invoked by uid 103); 15 Mar 2012 17:22:59 -0000
Received: from x16.dev (10.0.100.26) by x1.dev with QMQP; 15 Mar 2012 17:22:59 -0000
Received: from mail-gx0-f178.google.com (HELO mail-gx0-f178.google.com) (209.85.161.178) by 16.mx.develooper.com (qpsmtpd/0.80/v0.80-19-gf52d165) with ESMTP; Thu, 15 Mar 2012 10:22:56 -0700
Received: by ggno1 with SMTP id o1so3394332ggn.9 for <bug-Perl-Critic@rt.cpan.org>; Thu, 15 Mar 2012 10:22:53 -0700 (PDT)
Received: by 10.68.130.72 with SMTP id oc8mr6297231pbb.115.1331832173257; Thu, 15 Mar 2012 10:22:53 -0700 (PDT)
Received: from callahan.wifi.gene.com (fgt-rwc-ext-open.gene.com. [72.34.128.250]) by mx.google.com with ESMTPS id k3sm2305158pbd.17.2012.03.15.10.22.51 (version=TLSv1/SSLv3 cipher=OTHER); Thu, 15 Mar 2012 10:22:52 -0700 (PDT)
Delivered-To: cpan-bug+Perl-Critic@hipster.bestpractical.com
Subject: Re: [rt.cpan.org #75794] Suggested policy: /r flag on substitutions
Return-Path: <jeff@imaginative-software.com>
X-Spam-Check-BY: 16.mx.develooper.com
X-Original-To: cpan-bug+Perl-Critic@hipster.bestpractical.com
X-RT-Mail-Extension: perl-critic
X-Google-Dkim-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=content-type:mime-version:subject:from:in-reply-to:date :content-transfer-encoding:message-id:references:to:x-mailer :x-gm-message-state; bh=MCn5s1sIvcax39vHpZMr1gRTY+8wdLjQMRlBkCrtzcc=; b=Vs1wWTlmRE1v7fsSr68tjWku0/YncpwR25bxSiKbXhp9QRUpamHhooiJnYHVuxH+C3 59cbh1RSGk29i8DNfOSf9d9ZZu7dWvSuveIw5ISU7RtxRr9O6ojWLITkQ2FyRNOOalNF lRJrtNbQUn+7saJ/UOHbdp2XnrMe0oYDCj9fGlX0NHSPIKyU5SNfT08xJNn8hbvLHVmq VIrcqlYnSypcfWlFBPTYXNwEYgcS3blJQPXfH4Cs4es/T5FBrSQre3eokqAvuYwbFttX wazX8JkZybBRZJ3PFtZmeHugKixGIkv0QOUsMMn0wIS1QpMof53wBM1Dk6aMnWXmG67H 5Qcw==
Date: Thu, 15 Mar 2012 10:22:50 -0700
X-Spam-Level:
To: bug-Perl-Critic@rt.cpan.org
Content-Transfer-Encoding: quoted-printable
From: Jeffrey Thalhammer <jeff@imaginative-software.com>
X-GM-Message-State: ALoCoQl6t7BpnJnL8SLjv2VB30YyPuDqkcRmZ77NWgpyXp3w95KIGTG/cHsBRcq8rMXz0fIrfVr5
RT-Message-ID: <rt-3.8.HEAD-10815-1331832182-1637.75794-0-0@rt.cpan.org>
Content-Length: 886
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
MIME-Version: 1.0
In-Reply-To: <rt-3.8.HEAD-10815-1331832182-1637.75794-0-0@rt.cpan.org>
X-Mailer: MIME-tools 5.427 (Entity 5.427)
Content-Disposition: inline
References: <RT-Ticket-75794@rt.cpan.org> <rt-3.8.HEAD-10809-1331831401-11.75794-4-0@rt.cpan.org> <2CFB713A-D8C7-46A3-A21A-9BB2946BEBFA@imaginative-software.com> <rt-3.8.HEAD-10815-1331832182-1637.75794-0-0@rt.cpan.org>
Content-Type: text/plain; charset="UTF-8"
Message-ID: <rt-3.8.HEAD-10814-1332237025-708.75794-0-0@rt.cpan.org>
Content-Transfer-Encoding: binary
X-RT-Original-Encoding: utf-8
Content-Length: 188
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 runs on Request Tracker, is sponsored by The Perl Foundation, and maintained by Best Practical Solutions.

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