From 8f00d84afc0dad577b65df5a313e5306cee3d11f Mon Sep 17 00:00:00 2001 From: Andrew Dunstan Date: Mon, 13 Apr 2020 12:06:11 -0400 Subject: [PATCH] Use perl's $/ more idiomatically 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 | 5 +---- src/tools/msvc/Project.pm | 10 ++-------- src/tools/win32tzlist.pl | 9 +++++---- 3 files changed, 8 insertions(+), 16 deletions(-) diff --git a/src/tools/msvc/Install.pm b/src/tools/msvc/Install.pm index 1a92ed233a..e65ac6fc66 100644 --- a/src/tools/msvc/Install.pm +++ b/src/tools/msvc/Install.pm @@ -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; } diff --git a/src/tools/msvc/Project.pm b/src/tools/msvc/Project.pm index d90a996d46..20f79b382b 100644 --- a/src/tools/msvc/Project.pm +++ b/src/tools/msvc/Project.pm @@ -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; } diff --git a/src/tools/win32tzlist.pl b/src/tools/win32tzlist.pl index 25f7efbc58..97484016bb 100755 --- a/src/tools/win32tzlist.pl +++ b/src/tools/win32tzlist.pl @@ -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