From 8fe653087ba5b57f03bab4b7b3be0e072b32e839 Mon Sep 17 00:00:00 2001 From: Guillem Jover Date: Tue, 6 May 2025 20:49:58 +0200 Subject: [PATCH] MT#62763 Use a scoped variable instead of a local bareword Warned-by: perlcritic Fixes: Variables::RequireInitializationForLocalVars Fixes: InputOutput::ProhibitBarewordDirHandles Fixes: InputOutput::ProhibitBarewordFileHandles Change-Id: I835b434ac548540057f5540ea2a76dc9b68232e0 --- sandbox/generate_logfile_data_inventory.pl | 26 ++++++++++------------ 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/sandbox/generate_logfile_data_inventory.pl b/sandbox/generate_logfile_data_inventory.pl index 5e166d0190..86bf33a441 100644 --- a/sandbox/generate_logfile_data_inventory.pl +++ b/sandbox/generate_logfile_data_inventory.pl @@ -152,35 +152,33 @@ sub _scandirfiles { my ($inputdir,$slurp,$code) = @_; - local *DIR; - if (not opendir(DIR, $inputdir)) { - die('cannot opendir ' . $inputdir . ': ' . $!); - } - my @files = grep { /$rperlextensions$/ && -f $inputdir . $_} readdir(DIR); - closedir DIR; + opendir my $dir_dh, $inputdir + or die 'cannot opendir ' . $inputdir . ': ' . $!; + my @files = grep { + /$rperlextensions$/ && -f $inputdir . $_ + } readdir $dir_dh; + closedir $dir_dh; return unless (scalar @files) > 0; foreach my $file (@files) { my $inputfilepath = $inputdir . $file; next if grep { $_ eq $inputfilepath; } @filestoskip; my ($inputfilename,$inputfiledir,$inputfilesuffix) = File::Basename::fileparse($inputfilepath, $rperlextensions); - local *FILE; - if (not open (FILE,'<' . $inputfilepath)) { - die('cannot open file ' . $inputfilepath . ': ' . $!); - } + open my $fh, '<' . $inputfilepath + or die 'cannot open file ' . $inputfilepath . ': ' . $!; if ($slurp) { my $line_terminator = $/; $/ = undef; - my $data = ; + my $data = <$fh>; &$code(\$data,$inputfilename,$inputfiledir,$inputfilesuffix); $/ = $line_terminator; } else { - while () { + while (<$fh>) { last unless &$code($_,$inputfilename,$inputfiledir,$inputfilesuffix, sub { - ; + <$fh>; }); } } - close(FILE); + close $fh; } }