From: ilmari@ilmari.org
To: Andrew Dunstan <andrew.dunstan@2ndquadrant.com>
Cc: Tom Lane <tgl@sss.pgh.pa.us>
Cc: Peter Eisentraut <peter_e@gmx.net>
Cc: pgsql-hackers@postgresql.org
Subject: Re: [COMMITTERS] pgsql: Clean up Perl code according to perlcritic
Date: Tue, 28 Mar 2017 12:44:51 +0100
Message-ID: <d8jefxhvd58.fsf@dalvik.ping.uio.no> (raw)
In-Reply-To: <837eb7fd-55bb-1dc6-4727-ca472b0aaaf6@2ndQuadrant.com>
References: <E1csTgB-0003xZ-3P@gemulon.postgresql.org>
<14575.1490652977@sss.pgh.pa.us>
<4193.1490662733@sss.pgh.pa.us>
<d8jvaqtvjo2.fsf@dalvik.ping.uio.no>
<837eb7fd-55bb-1dc6-4727-ca472b0aaaf6@2ndQuadrant.com>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-hackers>
Andrew Dunstan <andrew.dunstan@2ndquadrant.com> writes:
> On 03/28/2017 05:23 AM, Dagfinn Ilmari Mannsåker wrote:
>> + @opts = grep { !/\$\(/ && /^--/ }
>> + map { (my $x = $_) =~ s/\Q$(top_builddir)\E/\"$topdir\"/; $x;}
>> + split(/\s+/, $1);
>>
>
> The use of this lexical $x variable seems entirely pointless and
> obfuscatory. If perlcritic doesn't like it without then that's another
> black mark against it IMNSHO.
The lexical copy is not strictly necessary in this case, because the
values we're mapping over are mutable temporaries returned by split().
An alternative form would be:
@opts = grep { !/\$\(/ && /^--/ }
map { s/\Q$(top_builddir)\E/\"$topdir\"/; $_ }
split(/\s+/, $1);
Perlcritic complains about that, though:
src/tools/msvc/vcregress.pl: Don't modify $_ in list functions at line
524, column 4. See page 114 of PBP. (Severity: 5)
This for two reasons:
1) If we were mapping over an array varible it would modify the original
values in-place (since $_ is an alias, not a copy).
2) If the list were to contain read-only items it'd throw a
"Modification of a read-only value attempted" exception.
The /r modifier was introduced in perl 5.14 exactly for this reason: it
makes the substitution non-destructive and returns the modified string
instead. However, we still support perls as ancient as 5.8, so we can't
use that.
- ilmari
--
- Twitter seems more influential [than blogs] in the 'gets reported in
the mainstream press' sense at least. - Matt McLeod
- That'd be because the content of a tweet is easier to condense down
to a mainstream media article. - Calle Dybedahl
--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-committers@postgresql.org
Cc: ilmari@ilmari.org, andrew.dunstan@2ndquadrant.com, tgl@sss.pgh.pa.us, peter_e@gmx.net, pgsql-hackers@postgresql.org
Subject: Re: [COMMITTERS] pgsql: Clean up Perl code according to perlcritic
In-Reply-To: <d8jefxhvd58.fsf@dalvik.ping.uio.no>
References: <E1csTgB-0003xZ-3P@gemulon.postgresql.org> <14575.1490652977@sss.pgh.pa.us> <4193.1490662733@sss.pgh.pa.us> <d8jvaqtvjo2.fsf@dalvik.ping.uio.no> <837eb7fd-55bb-1dc6-4727-ca472b0aaaf6@2ndQuadrant.com> <d8jefxhvd58.fsf@dalvik.ping.uio.no>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox