Re: [HACKERS] use strict in all Perl programs

2017-01-06 Thread Michael Paquier
On Fri, Jan 6, 2017 at 11:13 PM, David Steele  wrote:
> With regard to warnings, I prefer to use:
>
> use warnings FATAL => qw(all);
>
> This transforms all warnings into errors rather than just printing a message
> to stderr, which is very easy to miss among the other output.

Interesting. A couple of warnings have slipped a couple of times in
some TAP tests like those of pg_rewind, so it could be useful to
switch to that at least for the tests by detault.
-- 
Michael


-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers


Re: [HACKERS] use strict in all Perl programs

2017-01-06 Thread David Steele

On 1/5/17 12:37 PM, Peter Eisentraut wrote:

On 12/31/16 1:34 AM, Michael Paquier wrote:

On Sat, Dec 31, 2016 at 3:07 PM, Peter Eisentraut
 wrote:

Here is a patch to add 'use strict' to all Perl programs (that I could
find), or move it to the right place where it was already there.  I
think that is a pretty standard thing to do nowadays.


committed that


What about adding as well "use warnings"? That's standard in all the TAP tests.


'use strict' can be statically checked using perl -c, but 'use warnings'
is run-time behavior, so one would have to extensively test the involved
programs.  Some cursory checking already reveals that this is going to
need to more investigation.  So in principle yes, but maybe later.


With regard to warnings, I prefer to use:

use warnings FATAL => qw(all);

This transforms all warnings into errors rather than just printing a 
message to stderr, which is very easy to miss among the other output.


--
-David
da...@pgmasters.net


--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers


Re: [HACKERS] use strict in all Perl programs

2017-01-05 Thread Peter Eisentraut
On 12/31/16 1:34 AM, Michael Paquier wrote:
> On Sat, Dec 31, 2016 at 3:07 PM, Peter Eisentraut
>  wrote:
>> Here is a patch to add 'use strict' to all Perl programs (that I could
>> find), or move it to the right place where it was already there.  I
>> think that is a pretty standard thing to do nowadays.

committed that

> What about adding as well "use warnings"? That's standard in all the TAP 
> tests.

'use strict' can be statically checked using perl -c, but 'use warnings'
is run-time behavior, so one would have to extensively test the involved
programs.  Some cursory checking already reveals that this is going to
need to more investigation.  So in principle yes, but maybe later.

-- 
Peter Eisentraut  http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services


-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers


Re: [HACKERS] use strict in all Perl programs

2016-12-30 Thread Michael Paquier
On Sat, Dec 31, 2016 at 3:07 PM, Peter Eisentraut
 wrote:
> Here is a patch to add 'use strict' to all Perl programs (that I could
> find), or move it to the right place where it was already there.  I
> think that is a pretty standard thing to do nowadays.
>
> I tried testing the changes in pgcheckdefines, but it just spits out
> nonsense before and after.

What about adding as well "use warnings"? That's standard in all the TAP tests.
-- 
Michael


-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers


[HACKERS] use strict in all Perl programs

2016-12-30 Thread Peter Eisentraut
Here is a patch to add 'use strict' to all Perl programs (that I could
find), or move it to the right place where it was already there.  I
think that is a pretty standard thing to do nowadays.

I tried testing the changes in pgcheckdefines, but it just spits out
nonsense before and after.

-- 
Peter Eisentraut  http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services
>From 6db551f6ba2a9339051ecc7cabeb29ff59de2b26 Mon Sep 17 00:00:00 2001
From: Peter Eisentraut 
Date: Sun, 4 Dec 2016 12:00:00 -0500
Subject: [PATCH 1/2] Use 'use strict' in all Perl programs

---
 contrib/seg/seg-validate.pl| 35 +++---
 contrib/seg/sort-segments.pl   | 10 +--
 doc/src/sgml/mk_feature_tables.pl  |  2 ++
 src/pl/plperl/plc_perlboot.pl  |  2 ++
 src/test/locale/sort-test.pl   |  2 ++
 src/tools/msvc/build.pl|  4 ++-
 src/tools/msvc/gendef.pl   |  6 ++--
 src/tools/msvc/pgflex.pl   |  6 ++--
 src/tools/pginclude/pgcheckdefines | 59 ++
 src/tools/version_stamp.pl | 18 
 10 files changed, 87 insertions(+), 57 deletions(-)

diff --git a/contrib/seg/seg-validate.pl b/contrib/seg/seg-validate.pl
index cb3fb9a099..b8957ed984 100755
--- a/contrib/seg/seg-validate.pl
+++ b/contrib/seg/seg-validate.pl
@@ -1,20 +1,23 @@
 #!/usr/bin/perl
-$integer = '[+-]?[0-9]+';
-$real= '[+-]?[0-9]+\.[0-9]+';
-
-$RANGE = '(\.\.)(\.)?';
-$PLUMIN= q(\'\+\-\');
-$FLOAT = "(($integer)|($real))([eE]($integer))?";
-$EXTENSION = '<|>|~';
-
-$boundary  = "($EXTENSION)?$FLOAT";
-$deviation = $FLOAT;
-
-$rule_1 = $boundary . $PLUMIN . $deviation;
-$rule_2 = $boundary . $RANGE . $boundary;
-$rule_3 = $boundary . $RANGE;
-$rule_4 = $RANGE . $boundary;
-$rule_5 = $boundary;
+
+use strict;
+
+my $integer = '[+-]?[0-9]+';
+my $real= '[+-]?[0-9]+\.[0-9]+';
+
+my $RANGE = '(\.\.)(\.)?';
+my $PLUMIN= q(\'\+\-\');
+my $FLOAT = "(($integer)|($real))([eE]($integer))?";
+my $EXTENSION = '<|>|~';
+
+my $boundary  = "($EXTENSION)?$FLOAT";
+my $deviation = $FLOAT;
+
+my $rule_1 = $boundary . $PLUMIN . $deviation;
+my $rule_2 = $boundary . $RANGE . $boundary;
+my $rule_3 = $boundary . $RANGE;
+my $rule_4 = $RANGE . $boundary;
+my $rule_5 = $boundary;
 
 
 print "$rule_5\n";
diff --git a/contrib/seg/sort-segments.pl b/contrib/seg/sort-segments.pl
index a465468d5b..04eafd92f2 100755
--- a/contrib/seg/sort-segments.pl
+++ b/contrib/seg/sort-segments.pl
@@ -2,6 +2,10 @@
 
 # this script will sort any table with the segment data type in its last column
 
+use strict;
+
+my @rows;
+
 while (<>)
 {
 	chomp;
@@ -10,11 +14,11 @@
 
 foreach (
 	sort {
-		@ar = split("\t", $a);
-		$valA = pop @ar;
+		my @ar = split("\t", $a);
+		my $valA = pop @ar;
 		$valA =~ s/[~<> ]+//g;
 		@ar = split("\t", $b);
-		$valB = pop @ar;
+		my $valB = pop @ar;
 		$valB =~ s/[~<> ]+//g;
 		$valA <=> $valB
 	} @rows)
diff --git a/doc/src/sgml/mk_feature_tables.pl b/doc/src/sgml/mk_feature_tables.pl
index 45dea798cd..93dab2132e 100644
--- a/doc/src/sgml/mk_feature_tables.pl
+++ b/doc/src/sgml/mk_feature_tables.pl
@@ -2,6 +2,8 @@
 
 # doc/src/sgml/mk_feature_tables.pl
 
+use strict;
+
 my $yesno = $ARGV[0];
 
 open PACK, $ARGV[1] or die;
diff --git a/src/pl/plperl/plc_perlboot.pl b/src/pl/plperl/plc_perlboot.pl
index d506d01163..bb2d009be0 100644
--- a/src/pl/plperl/plc_perlboot.pl
+++ b/src/pl/plperl/plc_perlboot.pl
@@ -1,5 +1,7 @@
 #  src/pl/plperl/plc_perlboot.pl
 
+use strict;
+
 use 5.008001;
 use vars qw(%_SHARED $_TD);
 
diff --git a/src/test/locale/sort-test.pl b/src/test/locale/sort-test.pl
index ce7b93c571..cb7e4934e4 100755
--- a/src/test/locale/sort-test.pl
+++ b/src/test/locale/sort-test.pl
@@ -1,4 +1,6 @@
 #! /usr/bin/perl
+
+use strict;
 use locale;
 
 open(INFILE, "<$ARGV[0]");
diff --git a/src/tools/msvc/build.pl b/src/tools/msvc/build.pl
index a5469cd289..2e7c54853a 100644
--- a/src/tools/msvc/build.pl
+++ b/src/tools/msvc/build.pl
@@ -2,6 +2,8 @@
 
 # src/tools/msvc/build.pl
 
+use strict;
+
 BEGIN
 {
 
@@ -68,6 +70,6 @@ BEGIN
 
 # report status
 
-$status = $? >> 8;
+my $status = $? >> 8;
 
 exit $status;
diff --git a/src/tools/msvc/gendef.pl b/src/tools/msvc/gendef.pl
index a6c43c2c39..3bcff7ffaf 100644
--- a/src/tools/msvc/gendef.pl
+++ b/src/tools/msvc/gendef.pl
@@ -1,11 +1,11 @@
-my @def;
-
-use warnings;
 use strict;
+use warnings;
 use 5.8.0;
 use File::Spec::Functions qw(splitpath catpath);
 use List::Util qw(max);
 
+my @def;
+
 #
 # Script that generates a .DEF file for all objects in a directory
 #
diff --git a/src/tools/msvc/pgflex.pl b/src/tools/msvc/pgflex.pl
index 474ce63e5c..3a42add0d2 100644
--- a/src/tools/msvc/pgflex.pl
+++ b/src/tools/msvc/pgflex.pl
@@ -2,12 +2,12 @@
 
 # src/tools/msvc/pgflex.pl
 
-# silence flex bleatings about file path style
-$ENV{CYGWIN} = 'nodosfilewarning';
-
 use strict;
 use File::Basename;
 
+# silence flex bleatings about