Use perl's $/ more idiomatically
authorAndrew Dunstan <andrew@dunslane.net>
Mon, 13 Apr 2020 16:06:11 +0000 (12:06 -0400)
committerAndrew Dunstan <andrew@dunslane.net>
Mon, 13 Apr 2020 16:06:11 +0000 (12:06 -0400)
This replaces a few occurrences of ugly code with a more clean and
idiomatic usage. The problem was highlighted by perlcritic, but we're
not enforcing the policy that led to the discovery.

Discussion: https://postgr.es/m/20200412074245.GB623763@rfd.leadboat.com

src/tools/msvc/Install.pm
src/tools/msvc/Project.pm
src/tools/win32tzlist.pl

index 1a92ed233abca49819c352b38d3e27ca268a541a..e65ac6fc664a760da9183eb36c5e154ce96f7a06 100644 (file)
@@ -762,13 +762,10 @@ sub read_file
 {
    my $filename = shift;
    my $F;
-   my $t = $/;
-
-   undef $/;
+   local $/ = undef;
    open($F, '<', $filename) || die "Could not open file $filename\n";
    my $txt = <$F>;
    close($F);
-   $/ = $t;
 
    return $txt;
 }
index d90a996d46728b4152857f8bce4075af80f979d1..20f79b382b1bcad52a7fb167dc76948a9e69412f 100644 (file)
@@ -420,13 +420,10 @@ sub read_file
 {
    my $filename = shift;
    my $F;
-   my $t = $/;
-
-   undef $/;
+   local $/ = undef;
    open($F, '<', $filename) || croak "Could not open file $filename\n";
    my $txt = <$F>;
    close($F);
-   $/ = $t;
 
    return $txt;
 }
@@ -435,15 +432,12 @@ sub read_makefile
 {
    my $reldir = shift;
    my $F;
-   my $t = $/;
-
-   undef $/;
+   local $/ = undef;
    open($F, '<', "$reldir/GNUmakefile")
      || open($F, '<', "$reldir/Makefile")
      || confess "Could not open $reldir/Makefile\n";
    my $txt = <$F>;
    close($F);
-   $/ = $t;
 
    return $txt;
 }
index 25f7efbc5883a5c0f8897954d671319a34e4e1ad..97484016bb958fda361798c3e6fa1e30de439623 100755 (executable)
@@ -60,12 +60,13 @@ $basekey->Close();
 # Fetch all timezones currently in the file
 #
 my @file_zones;
+my $pgtz;
 open(my $tzfh, '<', $tzfile) or die "Could not open $tzfile!\n";
-my $t = $/;
-undef $/;
-my $pgtz = <$tzfh>;
+{
+   local $/ = undef;
+   $pgtz = <$tzfh>;
+}
 close($tzfh);
-$/ = $t;
 
 # Attempt to locate and extract the complete win32_tzmap struct
 $pgtz =~ /win32_tzmap\[\] =\s+{\s+\/\*[^\/]+\*\/\s+(.+?)};/gs