summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGuillem Jover <guillem@debian.org>2012-12-30 01:35:10 +0100
committerGuillem Jover <guillem@debian.org>2013-04-28 00:18:01 +0200
commitfc4f53c4b7d0837bef169ce7cdc0abec124f2d7d (patch)
treefbf0010e0818db47250a8a04dcaa4fc8bace5f48
parent9b590b2a54670c919a638a336769ae0687b2e72b (diff)
downloaddpkg-fc4f53c4b7d0837bef169ce7cdc0abec124f2d7d.tar.gz
Use proper variables instead of barewords for filehandles
Fixes InputOutput::ProhibitBarewordFileHandles. Warned-by: perlcritic
-rw-r--r--dselect/methods/Dselect/Ftp.pm13
-rwxr-xr-xdselect/methods/ftp/install35
-rwxr-xr-xdselect/mkcurkeys.pl12
-rw-r--r--scripts/Dpkg/Arch.pm24
-rw-r--r--scripts/Dpkg/BuildFlags.pm6
-rw-r--r--scripts/Dpkg/Changelog/Parse.pm12
-rw-r--r--scripts/Dpkg/Shlibs/Objdump.pm6
-rw-r--r--scripts/Dpkg/Source/Archive.pm6
-rw-r--r--scripts/Dpkg/Source/Functions.pm4
-rw-r--r--scripts/Dpkg/Source/Package.pm25
-rw-r--r--scripts/Dpkg/Source/Package/V2.pm49
-rw-r--r--scripts/Dpkg/Source/Package/V3/bzr.pm6
-rw-r--r--scripts/Dpkg/Source/Package/V3/git.pm6
-rw-r--r--scripts/Dpkg/Source/Package/V3/quilt.pm22
-rw-r--r--scripts/Dpkg/Source/Quilt.pm37
-rwxr-xr-xscripts/dpkg-buildpackage.pl12
-rwxr-xr-xscripts/dpkg-checkbuilddeps.pl7
-rwxr-xr-xscripts/dpkg-distaddfile.pl14
-rwxr-xr-xscripts/dpkg-genchanges.pl14
-rwxr-xr-xscripts/dpkg-gencontrol.pl32
-rwxr-xr-xscripts/dpkg-gensymbols.pl6
-rwxr-xr-xscripts/dpkg-mergechangelogs.pl6
-rwxr-xr-xscripts/dpkg-name.pl6
-rwxr-xr-xscripts/dpkg-scansources.pl6
-rwxr-xr-xscripts/dpkg-shlibdeps.pl30
-rwxr-xr-xscripts/dpkg-source.pl6
-rw-r--r--scripts/t/600_Dpkg_Changelog.t6
-rw-r--r--scripts/t/800_Dpkg_IPC.t19
-rw-r--r--scripts/t/850_Dpkg_Compression.t12
-rw-r--r--src/t/100_dpkg_divert.t24
-rw-r--r--test/100_critic.t1
-rw-r--r--utils/t/100_update_alternatives.t6
32 files changed, 245 insertions, 225 deletions
diff --git a/dselect/methods/Dselect/Ftp.pm b/dselect/methods/Dselect/Ftp.pm
index 568e5f6f8..7f599a7b9 100644
--- a/dselect/methods/Dselect/Ftp.pm
+++ b/dselect/methods/Dselect/Ftp.pm
@@ -41,11 +41,11 @@ sub read_config {
my ($code, $conf);
local($/);
- open(VARS, '<', $vars) ||
+ open(my $vars_fh, '<', $vars) ||
die "Couldn't open $vars : $!\n" .
"Try to relaunch the 'Access' step in dselect, thanks.\n";
- $code = <VARS>;
- close VARS;
+ $code = <$vars_fh>;
+ close $vars_fh;
my $VAR1;
$conf = eval $code;
@@ -68,9 +68,10 @@ sub store_config {
# Check that config is completed
return if not $config{'done'};
- open(VARS, '>', $vars) || die "Couldn't open $vars in write mode : $!\n";
- print VARS Dumper(\%config);
- close VARS;
+ open(my $vars_fh, '>', $vars) ||
+ die "Couldn't open $vars in write mode : $!\n";
+ print $vars_fh Dumper(\%config);
+ close $vars_fh;
}
sub view_mirrors {
diff --git a/dselect/methods/ftp/install b/dselect/methods/ftp/install
index fdb1fc547..747742e54 100755
--- a/dselect/methods/ftp/install
+++ b/dselect/methods/ftp/install
@@ -61,10 +61,10 @@ mkpath(["$methdir/$config{'dldir'}"], 0, 0755);
my %md5sums;
if (-f "$methdir/md5sums") {
local $/;
- open(MD5SUMS, '<', "$methdir/md5sums") ||
+ open(my $md5sums_fh, '<', "$methdir/md5sums") ||
die "Couldn't read file $methdir/md5sums";
- my $code = <MD5SUMS>;
- close MD5SUMS;
+ my $code = <$md5sums_fh>;
+ close $md5sums_fh;
my $VAR1;
my $res = eval $code;
if ($@) {
@@ -114,8 +114,9 @@ print "Processing status file...\n";
my %curpkgs;
sub procstatus {
my (%flds, $fld);
- open (STATUS, '<', "$vardir/status") or die "Could not open status file";
- while (%flds = getblk(\*STATUS), %flds) {
+ open(my $status_fh, '<', "$vardir/status") or
+ die "Could not open status file";
+ while (%flds = getblk($status_fh), %flds) {
if($flds{'status'} =~ /^install ok/) {
my $cs = (split(/ /, $flds{'status'}))[2];
if(($cs eq "not-installed") ||
@@ -127,7 +128,7 @@ sub procstatus {
}
}
}
- close(STATUS);
+ close($status_fh);
}
procstatus();
@@ -156,8 +157,8 @@ sub procpkgfile {
my $dist = shift;
my(@files,@sizes,@md5sums,$pkg,$ver,$fl,$nfs,$fld);
my(%flds);
- open(PKGFILE, '<', $fn) or die "Could not open package file $fn";
- while(%flds = getblk(\*PKGFILE), %flds) {
+ open(my $pkgfile_fh, '<', $fn) or die "Could not open package file $fn";
+ while (%flds = getblk($pkgfile_fh), %flds) {
$pkg = $flds{'package'};
$ver = $curpkgs{$pkg};
@files = split(/[\s\n]+/, $flds{'filename'});
@@ -466,20 +467,20 @@ sub getdebinfo($) {
my $type = chkdeb($fn);
my ($pkg, $ver);
if($type == 1) {
- open(PKGFILE, '-|', "dpkg-deb --field $fn");
- my %fields = getblk(\*PKGFILE);
- close(PKGFILE);
+ open(my $pkgfile_fh, '-|', "dpkg-deb --field $fn");
+ my %fields = getblk($pkgfile_fh);
+ close($pkgfile_fh);
$pkg = $fields{'package'};
$ver = $fields{'version'};
if($fields{'package_revision'}) { $ver .= '-' . $fields{'package_revision'}; }
return $pkg, $ver;
} elsif ( $type == 2) {
- open(PKGFILE, '-|', "dpkg-split --info $fn");
- while(<PKGFILE>) {
+ open(my $pkgfile_fh, '-|', "dpkg-split --info $fn");
+ while (<$pkgfile_fh>) {
/Part of package:\s*(\S+)/ and $pkg = $+;
/\.\.\. version:\s*(\S+)/ and $ver = $+;
}
- close(PKGFILE);
+ close($pkgfile_fh);
return $pkg, $ver;
}
print "could not figure out type of $fn\n";
@@ -623,9 +624,9 @@ foreach (keys %md5sums) {
next if (-f $_);
delete $md5sums{$_};
}
-open(MD5SUMS, '>', "$methdir/md5sums") ||
+open(my $md5sums_fh, '>', "$methdir/md5sums") ||
die "Can't open $methdir/md5sums in write mode : $!\n";
-print MD5SUMS Dumper(\%md5sums);
-close MD5SUMS;
+print $md5sums_fh Dumper(\%md5sums);
+close $md5sums_fh;
exit $exit;
diff --git a/dselect/mkcurkeys.pl b/dselect/mkcurkeys.pl
index 244544c80..d4d4093d5 100755
--- a/dselect/mkcurkeys.pl
+++ b/dselect/mkcurkeys.pl
@@ -27,8 +27,8 @@ $#ARGV == 1 || die ("usage: mkcurkeys.pl <filename> <curses.h>");
my (%over, %base, %name);
-open(OV, '<', $ARGV[0]) || die $!;
-while (<OV>) {
+open(my $override_fh, '<', $ARGV[0]) || die $!;
+while (<$override_fh>) {
chomp;
/^#/ && next; # skip comments
/\S/ || next; # ignore blank lines
@@ -36,7 +36,7 @@ while (<OV>) {
$over{$1}= $2;
$base{$1}= '';
}
-close(OV);
+close($override_fh);
for (my $i = 1, my $let = 'A'; $i <= 26; $i++, $let++) {
$name{$i}= "^$let";
@@ -45,8 +45,8 @@ for (my $i = 1, my $let = 'A'; $i <= 26; $i++, $let++) {
our ($k, $v);
-open(NCH, '<', $ARGV[1]) || die $!;
-while (<NCH>) {
+open(my $header_fh, '<', $ARGV[1]) || die $!;
+while (<$header_fh>) {
s/\s+$//;
m/#define KEY_(\w+)\s+\d+\s+/ || next;
my $rhs = $';
@@ -64,7 +64,7 @@ while (<NCH>) {
capit();
$name{$k}= $_;
}
-close(NCH);
+close($header_fh);
printf(<<'END') || die $!;
/*
diff --git a/scripts/Dpkg/Arch.pm b/scripts/Dpkg/Arch.pm
index b2538b4ec..2c1471f9c 100644
--- a/scripts/Dpkg/Arch.pm
+++ b/scripts/Dpkg/Arch.pm
@@ -146,9 +146,9 @@ sub read_cputable
local $_;
local $/ = "\n";
- open CPUTABLE, '<', "$pkgdatadir/cputable"
+ open my $cputable_fh, '<', "$pkgdatadir/cputable"
or syserr(_g("cannot open %s"), "cputable");
- while (<CPUTABLE>) {
+ while (<$cputable_fh>) {
if (m/^(?!\#)(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)/) {
$cputable{$1} = $2;
$cputable_re{$1} = $3;
@@ -157,7 +157,7 @@ sub read_cputable
push @cpu, $1;
}
}
- close CPUTABLE;
+ close $cputable_fh;
$cputable_loaded = 1;
}
@@ -170,16 +170,16 @@ sub read_ostable
local $_;
local $/ = "\n";
- open OSTABLE, '<', "$pkgdatadir/ostable"
+ open my $ostable_fh, '<', "$pkgdatadir/ostable"
or syserr(_g("cannot open %s"), "ostable");
- while (<OSTABLE>) {
+ while (<$ostable_fh>) {
if (m/^(?!\#)(\S+)\s+(\S+)\s+(\S+)/) {
$ostable{$1} = $2;
$ostable_re{$1} = $3;
push @os, $1;
}
}
- close OSTABLE;
+ close $ostable_fh;
$ostable_loaded = 1;
}
@@ -196,13 +196,13 @@ sub abitable_load()
# it does not exist, as that will only mean the other tables do not have
# an entry needing to be overridden. This way we do not require a newer
# dpkg by libdpkg-perl.
- if (open ABITABLE, '<', "$pkgdatadir/abitable") {
- while (<ABITABLE>) {
+ if (open my $abitable_fh, '<', "$pkgdatadir/abitable") {
+ while (<$abitable_fh>) {
if (m/^(?!\#)(\S+)\s+(\S+)/) {
$abibits{$1} = $2;
}
}
- close ABITABLE;
+ close $abitable_fh;
} elsif ($! != ENOENT) {
syserr(_g("cannot open %s"), "abitable");
}
@@ -220,9 +220,9 @@ sub read_triplettable()
local $_;
local $/ = "\n";
- open TRIPLETTABLE, '<', "$pkgdatadir/triplettable"
+ open my $triplettable_fh, '<', "$pkgdatadir/triplettable"
or syserr(_g("cannot open %s"), "triplettable");
- while (<TRIPLETTABLE>) {
+ while (<$triplettable_fh>) {
if (m/^(?!\#)(\S+)\s+(\S+)/) {
my $debtriplet = $1;
my $debarch = $2;
@@ -241,7 +241,7 @@ sub read_triplettable()
}
}
}
- close TRIPLETTABLE;
+ close $triplettable_fh;
$triplettable_loaded = 1;
}
diff --git a/scripts/Dpkg/BuildFlags.pm b/scripts/Dpkg/BuildFlags.pm
index 27a26316d..e2e48d203 100644
--- a/scripts/Dpkg/BuildFlags.pm
+++ b/scripts/Dpkg/BuildFlags.pm
@@ -298,8 +298,8 @@ $source is the origin recorded for any build flag set or modified.
sub update_from_conffile {
my ($self, $file, $src) = @_;
return unless -e $file;
- open(CNF, "<", $file) or syserr(_g("cannot read %s"), $file);
- while(<CNF>) {
+ open(my $conf_fh, "<", $file) or syserr(_g("cannot read %s"), $file);
+ while (<$conf_fh>) {
chomp;
next if /^\s*#/; # Skip comments
next if /^\s*$/; # Skip empty lines
@@ -322,7 +322,7 @@ sub update_from_conffile {
warning(_g("line %d of %s is invalid, it has been ignored"), $., $file);
}
}
- close(CNF);
+ close($conf_fh);
}
=item $bf->get($flag)
diff --git a/scripts/Dpkg/Changelog/Parse.pm b/scripts/Dpkg/Changelog/Parse.pm
index f6d7e2d53..3b76ca987 100644
--- a/scripts/Dpkg/Changelog/Parse.pm
+++ b/scripts/Dpkg/Changelog/Parse.pm
@@ -99,11 +99,11 @@ sub changelog_parse {
# Extract the format from the changelog file if possible
unless($force or ($changelogfile eq "-")) {
- open(P, "-|", "tail", "-n", "40", $changelogfile);
- while(<P>) {
+ open(my $format_fh, "-|", "tail", "-n", "40", $changelogfile);
+ while (<$format_fh>) {
$format = $1 if m/\schangelog-format:\s+([0-9a-z]+)\W/;
}
- close(P) or subprocerr(_g("tail of %s"), $changelogfile);
+ close($format_fh) or subprocerr(_g("tail of %s"), $changelogfile);
}
# Find the right changelog parser
@@ -134,7 +134,7 @@ sub changelog_parse {
}
# Fork and call the parser
- my $pid = open(P, "-|");
+ my $pid = open(my $parser_fh, "-|");
syserr(_g("cannot fork for %s"), $parser) unless defined $pid;
if (not $pid) {
if ($changelogfile ne "-") {
@@ -148,10 +148,10 @@ sub changelog_parse {
my (@res, $fields);
while (1) {
$fields = Dpkg::Control::Changelog->new();
- last unless $fields->parse(\*P, _g("output of changelog parser"));
+ last unless $fields->parse($parser_fh, _g("output of changelog parser"));
push @res, $fields;
}
- close(P) or subprocerr(_g("changelog parser %s"), $parser);
+ close($parser_fh) or subprocerr(_g("changelog parser %s"), $parser);
if (wantarray) {
return @res;
} else {
diff --git a/scripts/Dpkg/Shlibs/Objdump.pm b/scripts/Dpkg/Shlibs/Objdump.pm
index 5652035cb..c0688a0fb 100644
--- a/scripts/Dpkg/Shlibs/Objdump.pm
+++ b/scripts/Dpkg/Shlibs/Objdump.pm
@@ -119,12 +119,12 @@ sub has_object {
sub is_elf {
my ($file) = @_;
- open(FILE, "<", $file) || syserr(_g("cannot read %s"), $file);
+ open(my $file_fh, "<", $file) || syserr(_g("cannot read %s"), $file);
my ($header, $result) = ("", 0);
- if (read(FILE, $header, 4) == 4) {
+ if (read($file_fh, $header, 4) == 4) {
$result = 1 if ($header =~ /^\177ELF$/);
}
- close(FILE);
+ close($file_fh);
return $result;
}
diff --git a/scripts/Dpkg/Source/Archive.pm b/scripts/Dpkg/Source/Archive.pm
index 39d6704a0..5ce625a14 100644
--- a/scripts/Dpkg/Source/Archive.pm
+++ b/scripts/Dpkg/Source/Archive.pm
@@ -141,9 +141,9 @@ sub extract {
return if $opts{"in_place"};
# Rename extracted directory
- opendir(D, $tmp) || syserr(_g("cannot opendir %s"), $tmp);
- my @entries = grep { $_ ne "." && $_ ne ".." } readdir(D);
- closedir(D);
+ opendir(my $dir_dh, $tmp) || syserr(_g("cannot opendir %s"), $tmp);
+ my @entries = grep { $_ ne "." && $_ ne ".." } readdir($dir_dh);
+ closedir($dir_dh);
my $done = 0;
erasedir($dest);
if (scalar(@entries) == 1 && ! -l "$tmp/$entries[0]" && -d _) {
diff --git a/scripts/Dpkg/Source/Functions.pm b/scripts/Dpkg/Source/Functions.pm
index 61d472b74..d88b896cc 100644
--- a/scripts/Dpkg/Source/Functions.pm
+++ b/scripts/Dpkg/Source/Functions.pm
@@ -75,8 +75,8 @@ sub fs_time($) {
my ($file) = @_;
my $is_temp = 0;
if (not -e $file) {
- open(TEMP, ">", $file) or syserr(_g("cannot write %s"));
- close(TEMP);
+ open(my $temp_fh, ">", $file) or syserr(_g("cannot write %s"));
+ close($temp_fh);
$is_temp = 1;
} else {
utime(undef, undef, $file) or
diff --git a/scripts/Dpkg/Source/Package.pm b/scripts/Dpkg/Source/Package.pm
index 7978f1095..8ea7c0a19 100644
--- a/scripts/Dpkg/Source/Package.pm
+++ b/scripts/Dpkg/Source/Package.pm
@@ -190,14 +190,14 @@ sub initialize {
$self->{'filename'} = $fn;
# Check if it contains a signature
- open(DSC, "<", $filename) || syserr(_g("cannot open %s"), $filename);
+ open(my $dsc_fh, "<", $filename) || syserr(_g("cannot open %s"), $filename);
$self->{'is_signed'} = 0;
- while (<DSC>) {
+ while (<$dsc_fh>) {
next if /^\s*$/o;
$self->{'is_signed'} = 1 if /^-----BEGIN PGP SIGNED MESSAGE-----\s*$/o;
last;
}
- close(DSC);
+ close($dsc_fh);
# Read the fields
my $fields = Dpkg::Control->new(type => CTRL_PKG_SRC);
$fields->load($filename);
@@ -305,14 +305,14 @@ sub find_original_tarballs {
my @tar;
foreach my $dir (".", $self->{'basedir'}, $self->{'options'}{'origtardir'}) {
next unless defined($dir) and -d $dir;
- opendir(DIR, $dir) || syserr(_g("cannot opendir %s"), $dir);
+ opendir(my $dir_dh, $dir) || syserr(_g("cannot opendir %s"), $dir);
push @tar, map { "$dir/$_" } grep {
($opts{include_main} and
/^\Q$basename\E\.orig\.tar\.$opts{extension}$/) or
($opts{include_supplementary} and
/^\Q$basename\E\.orig-[[:alnum:]-]+\.tar\.$opts{extension}$/)
- } readdir(DIR);
- closedir(DIR);
+ } readdir($dir_dh);
+ closedir($dir_dh);
}
return @tar;
}
@@ -445,9 +445,10 @@ sub extract {
my $format_file = File::Spec->catfile($srcdir, "format");
unless (-e $format_file) {
mkdir($srcdir) unless -e $srcdir;
- open(FORMAT, ">", $format_file) || syserr(_g("cannot write %s"), $format_file);
- print FORMAT $self->{'fields'}{'Format'} . "\n";
- close(FORMAT);
+ open(my $format_fh, ">", $format_file) ||
+ syserr(_g("cannot write %s"), $format_file);
+ print $format_fh $self->{'fields'}{'Format'} . "\n";
+ close($format_fh);
}
}
@@ -557,10 +558,10 @@ sub write_dsc {
unless (defined $filename) {
$filename = $self->get_basename(1) . ".dsc";
}
- open(DSC, ">", $filename) || syserr(_g("cannot write %s"), $filename);
+ open(my $dsc_fh, ">", $filename) || syserr(_g("cannot write %s"), $filename);
$fields->apply_substvars($opts{'substvars'});
- $fields->output(\*DSC);
- close(DSC);
+ $fields->output($dsc_fh);
+ close($dsc_fh);
}
=back
diff --git a/scripts/Dpkg/Source/Package/V2.pm b/scripts/Dpkg/Source/Package/V2.pm
index a9590fdb3..de1274769 100644
--- a/scripts/Dpkg/Source/Package/V2.pm
+++ b/scripts/Dpkg/Source/Package/V2.pm
@@ -200,14 +200,14 @@ sub get_patches {
my $pd = "$dir/debian/patches";
my $auto_patch = $self->get_autopatch_name();
if (-d $pd) {
- opendir(DIR, $pd) || syserr(_g("cannot opendir %s"), $pd);
- foreach my $patch (sort readdir(DIR)) {
+ opendir(my $dir_dh, $pd) || syserr(_g("cannot opendir %s"), $pd);
+ foreach my $patch (sort readdir($dir_dh)) {
# patches match same rules as run-parts
next unless $patch =~ /^[\w-]+$/ and -f "$pd/$patch";
next if $opts{"skip_auto"} and $patch eq $auto_patch;
push @patches, $patch;
}
- closedir(DIR);
+ closedir($dir_dh);
}
return @patches;
}
@@ -218,8 +218,9 @@ sub apply_patches {
my @patches = $self->get_patches($dir, %opts);
return unless scalar(@patches);
my $applied = File::Spec->catfile($dir, "debian", "patches", ".dpkg-source-applied");
- open(APPLIED, '>', $applied) || syserr(_g("cannot write %s"), $applied);
- print APPLIED "# During $opts{'usage'}\n";
+ open(my $applied_fh, '>', $applied) ||
+ syserr(_g("cannot write %s"), $applied);
+ print $applied_fh "# During $opts{'usage'}\n";
my $timestamp = fs_time($applied);
foreach my $patch ($self->get_patches($dir, %opts)) {
my $path = File::Spec->catfile($dir, "debian", "patches", $patch);
@@ -228,9 +229,9 @@ sub apply_patches {
$patch_obj->apply($dir, force_timestamp => 1,
timestamp => $timestamp,
add_options => [ '-E' ]);
- print APPLIED "$patch\n";
+ print $applied_fh "$patch\n";
}
- close(APPLIED);
+ close($applied_fh);
}
sub unapply_patches {
@@ -278,9 +279,10 @@ sub after_build {
my $applied = File::Spec->catfile($dir, "debian", "patches", ".dpkg-source-applied");
my $reason = "";
if (-e $applied) {
- open(APPLIED, "<", $applied) || syserr(_g("cannot read %s"), $applied);
- $reason = <APPLIED>;
- close(APPLIED);
+ open(my $applied_fh, "<", $applied) ||
+ syserr(_g("cannot read %s"), $applied);
+ $reason = <$applied_fh>;
+ close($applied_fh);
}
my $opt_unapply = $self->{'options'}{'unapply_patches'};
if (($opt_unapply eq "auto" and $reason =~ /^# During preparation/) or
@@ -546,9 +548,9 @@ sub get_patch_header {
}
my $text;
if (-f $ph) {
- open(PH, "<", $ph) || syserr(_g("cannot read %s"), $ph);
- $text = join("", <PH>);
- close(PH);
+ open(my $ph_fh, "<", $ph) || syserr(_g("cannot read %s"), $ph);
+ $text = join("", <$ph_fh>);
+ close($ph_fh);
return $text;
}
my $ch_info = changelog_parse(offset => 0, count => 1,
@@ -590,9 +592,10 @@ sub register_patch {
chmod(0666 & ~ umask(), $patch) ||
syserr(_g("unable to change permission of `%s'"), $patch);
my $applied = File::Spec->catfile($dir, "debian", "patches", ".dpkg-source-applied");
- open(APPLIED, '>>', $applied) || syserr(_g("cannot write %s"), $applied);
- print APPLIED "$patch\n";
- close(APPLIED) || syserr(_g("cannot close %s"), $applied);
+ open(my $applied_fh, '>>', $applied) ||
+ syserr(_g("cannot write %s"), $applied);
+ print $applied_fh "$patch\n";
+ close($applied_fh) || syserr(_g("cannot close %s"), $applied);
} elsif (-e $patch) {
unlink($patch) || syserr(_g("cannot remove %s"), $patch);
}
@@ -690,13 +693,14 @@ sub load_allowed_binaries {
my ($self) = @_;
my $incbin_file = $self->{'include_binaries_path'};
if (-f $incbin_file) {
- open(INC, "<", $incbin_file) || syserr(_g("cannot read %s"), $incbin_file);
- while(defined($_ = <INC>)) {
+ open(my $incbin_fh, "<", $incbin_file) ||
+ syserr(_g("cannot read %s"), $incbin_file);
+ while (defined($_ = <$incbin_fh>)) {
chomp; s/^\s*//; s/\s*$//;
next if /^#/ or /^$/;
$self->{'allowed_binaries'}{$_} = 1;
}
- close(INC);
+ close($incbin_fh);
}
}
@@ -714,13 +718,14 @@ sub update_debian_source_include_binaries {
my $incbin_file = $self->{'include_binaries_path'};
mkpath(File::Spec->catdir($self->{'dir'}, "debian", "source"));
- open(INC, ">>", $incbin_file) || syserr(_g("cannot write %s"), $incbin_file);
+ open(my $incbin_fh, ">>", $incbin_file) ||
+ syserr(_g("cannot write %s"), $incbin_file);
foreach my $binary (@unknown_binaries) {
- print INC "$binary\n";
+ print $incbin_fh "$binary\n";
info(_g("adding %s to %s"), $binary, "debian/source/include-binaries");
$self->{'allowed_binaries'}{$binary} = 1;
}
- close(INC);
+ close($incbin_fh);
}
sub get_unknown_binaries {
diff --git a/scripts/Dpkg/Source/Package/V3/bzr.pm b/scripts/Dpkg/Source/Package/V3/bzr.pm
index c9794dfae..08bbd13af 100644
--- a/scripts/Dpkg/Source/Package/V3/bzr.pm
+++ b/scripts/Dpkg/Source/Package/V3/bzr.pm
@@ -114,10 +114,10 @@ sub do_build {
# Check for uncommitted files.
# To support dpkg-source -i, remove any ignored files from the
# output of bzr status.
- open(BZR_STATUS, '-|', "bzr", "status") ||
+ open(my $bzr_status_fh, '-|', "bzr", "status") ||
subprocerr("bzr status");
my @files;
- while (<BZR_STATUS>) {
+ while (<$bzr_status_fh>) {
chomp;
next unless s/^ +//;
if (! length $diff_ignore_regexp ||
@@ -125,7 +125,7 @@ sub do_build {
push @files, $_;
}
}
- close(BZR_STATUS) || syserr(_g("bzr status exited nonzero"));
+ close($bzr_status_fh) || syserr(_g("bzr status exited nonzero"));
if (@files) {
error(_g("uncommitted, not-ignored changes in working directory: %s"),
join(" ", @files));
diff --git a/scripts/Dpkg/Source/Package/V3/git.pm b/scripts/Dpkg/Source/Package/V3/git.pm
index d4cd53630..998fdb826 100644
--- a/scripts/Dpkg/Source/Package/V3/git.pm
+++ b/scripts/Dpkg/Source/Package/V3/git.pm
@@ -116,11 +116,11 @@ sub do_build {
if (-e ".git/info/exclude") {
push @ignores, "--exclude-from=.git/info/exclude";
}
- open(GIT_LS_FILES, '-|', "git", "ls-files", "--modified", "--deleted",
+ open(my $git_ls_files_fh, '-|', "git", "ls-files", "--modified", "--deleted",
"-z", "--others", @ignores) || subprocerr("git ls-files");
my @files;
{ local $/ = "\0";
- while (<GIT_LS_FILES>) {
+ while (<$git_ls_files_fh>) {
chomp;
if (! length $diff_ignore_regexp ||
! m/$diff_ignore_regexp/o) {
@@ -128,7 +128,7 @@ sub do_build {
}
}
}
- close(GIT_LS_FILES) || syserr(_g("git ls-files exited nonzero"));
+ close($git_ls_files_fh) || syserr(_g("git ls-files exited nonzero"));
if (@files) {
error(_g("uncommitted, not-ignored changes in working directory: %s"),
join(" ", @files));
diff --git a/scripts/Dpkg/Source/Package/V3/quilt.pm b/scripts/Dpkg/Source/Package/V3/quilt.pm
index 45f2e8799..3b7d0e319 100644
--- a/scripts/Dpkg/Source/Package/V3/quilt.pm
+++ b/scripts/Dpkg/Source/Package/V3/quilt.pm
@@ -123,9 +123,9 @@ sub apply_patches {
# We're applying the patches in --before-build, remember to unapply
# them afterwards in --after-build
my $pc_unapply = $quilt->get_db_file(".dpkg-source-unapply");
- open(UNAPPLY, ">", $pc_unapply) ||
+ open(my $unapply_fh, ">", $pc_unapply) ||
syserr(_g("cannot write %s"), $pc_unapply);
- close(UNAPPLY);
+ close($unapply_fh);
}
# Apply patches
@@ -219,19 +219,19 @@ sub register_patch {
sub add_line {
my ($file, $line) = @_;
- open(FILE, ">>", $file) || syserr(_g("cannot write %s"), $file);
- print FILE "$line\n";
- close(FILE);
+ open(my $file_fh, ">>", $file) || syserr(_g("cannot write %s"), $file);
+ print $file_fh "$line\n";
+ close($file_fh);
}
sub drop_line {
my ($file, $re) = @_;
- open(FILE, "<", $file) || syserr(_g("cannot read %s"), $file);
- my @lines = <FILE>;
- close(FILE);
- open(FILE, ">", $file) || syserr(_g("cannot write %s"), $file);
- print(FILE $_) foreach grep { not /^\Q$re\E\s*$/ } @lines;
- close(FILE);
+ open(my $file_fh, "<", $file) || syserr(_g("cannot read %s"), $file);
+ my @lines = <$file_fh>;
+ close($file_fh);
+ open($file_fh, ">", $file) || syserr(_g("cannot write %s"), $file);
+ print($file_fh $_) foreach grep { not /^\Q$re\E\s*$/ } @lines;
+ close($file_fh);
}
my $quilt = $self->build_quilt_object($dir);
diff --git a/scripts/Dpkg/Source/Quilt.pm b/scripts/Dpkg/Source/Quilt.pm
index e61331f91..a0c98f63a 100644
--- a/scripts/Dpkg/Source/Quilt.pm
+++ b/scripts/Dpkg/Source/Quilt.pm
@@ -55,26 +55,26 @@ sub setup_db {
}
my $file = $self->get_db_file(".version");
if (not -e $file) {
- open(VERSION, ">", $file) or syserr(_g("cannot write %s"), $file);
- print VERSION "2\n";
- close(VERSION);
+ open(my $version_fh, ">", $file) or syserr(_g("cannot write %s"), $file);
+ print $version_fh "2\n";
+ close($version_fh);
}
# The files below are used by quilt to know where patches are stored
# and what file contains the patch list (supported by quilt >= 0.48-5
# in Debian).
$file = $self->get_db_file(".quilt_patches");
if (not -e $file) {
- open(QPATCH, ">", $file) or syserr(_g("cannot write %s"), $file);
- print QPATCH "debian/patches\n";
- close(QPATCH);
+ open(my $qpatch_fh, ">", $file) or syserr(_g("cannot write %s"), $file);
+ print $qpatch_fh "debian/patches\n";
+ close($qpatch_fh);
}
$file = $self->get_db_file(".quilt_series");
if (not -e $file) {
- open(QSERIES, ">", $file) or syserr(_g("cannot write %s"), $file);
+ open(my $qseries_fh, ">", $file) or syserr(_g("cannot write %s"), $file);
my $series = $self->get_series_file();
$series = (File::Spec->splitpath($series))[2];
- print QSERIES "$series\n";
- close(QSERIES);
+ print $qseries_fh "$series\n";
+ close($qseries_fh);
}
}
@@ -90,11 +90,12 @@ sub write_db {
$self->setup_db();
my $pc_applied = $self->get_db_file("applied-patches");
- open(APPLIED, ">", $pc_applied) or syserr(_g("cannot write %s"), $pc_applied);
+ open(my $applied_fh, ">", $pc_applied) or
+ syserr(_g("cannot write %s"), $pc_applied);
foreach my $patch (@{$self->{'applied-patches'}}) {
- print APPLIED "$patch\n";
+ print $applied_fh "$patch\n";
}
- close(APPLIED);
+ close($applied_fh);
}
sub load_series {
@@ -196,10 +197,10 @@ sub get_db_version {
my ($self) = @_;
my $pc_ver = $self->get_db_file(".version");
if (-f $pc_ver) {
- open(VER, "<", $pc_ver) || syserr(_g("cannot read %s"), $pc_ver);
- my $version = <VER>;
+ open(my $ver_fh, "<", $pc_ver) || syserr(_g("cannot read %s"), $pc_ver);
+ my $version = <$ver_fh>;
chomp $version;
- close(VER);
+ close($ver_fh);
return $version;
}
return;
@@ -255,8 +256,8 @@ sub read_patch_list {
return () if not defined $file or not -f $file;
$opts{"warn_options"} = 0 unless defined($opts{"warn_options"});
my @patches;
- open(SERIES, "<" , $file) || syserr(_g("cannot read %s"), $file);
- while(defined($_ = <SERIES>)) {
+ open(my $series_fh, "<" , $file) || syserr(_g("cannot read %s"), $file);
+ while (defined($_ = <$series_fh>)) {
chomp; s/^\s+//; s/\s+$//; # Strip leading/trailing spaces
s/(^|\s+)#.*$//; # Strip comment
next unless $_;
@@ -272,7 +273,7 @@ sub read_patch_list {
error(_g("%s contains an insecure path: %s"), $file, $_) if m{(^|/)\.\./};
CORE::push @patches, $_;
}
- close(SERIES);
+ close($series_fh);
return @patches;
}
diff --git a/scripts/dpkg-buildpackage.pl b/scripts/dpkg-buildpackage.pl
index 6650e9045..78485cb27 100755
--- a/scripts/dpkg-buildpackage.pl
+++ b/scripts/dpkg-buildpackage.pl
@@ -446,14 +446,14 @@ if (defined($desc)) { push @changes_opts, "-C$desc" }
my $chg = "../$pva.changes";
print STDERR " dpkg-genchanges @changes_opts >$chg\n";
-open CHANGES, '-|', 'dpkg-genchanges', @changes_opts
+open my $changes_fh, '-|', 'dpkg-genchanges', @changes_opts
or subprocerr('dpkg-genchanges');
-open OUT, '>', $chg or syserr(_g('write changes file'));
+open my $out_fh, '>', $chg or syserr(_g('write changes file'));
my $infiles = my $files = '';
-while ($_ = <CHANGES>) {
- print OUT $_ or syserr(_g('write changes file'));
+while ($_ = <$changes_fh>) {
+ print $out_fh $_ or syserr(_g('write changes file'));
chomp;
if (/^Files:/i) {
@@ -465,8 +465,8 @@ while ($_ = <CHANGES>) {
}
}
-close CHANGES or subprocerr(_g('dpkg-genchanges'));
-close OUT or syserr(_g('write changes file'));
+close $changes_fh or subprocerr(_g('dpkg-genchanges'));
+close $out_fh or syserr(_g('write changes file'));
my $srcmsg;
sub fileomitted($) { return $files !~ /$_[0]/ }
diff --git a/scripts/dpkg-checkbuilddeps.pl b/scripts/dpkg-checkbuilddeps.pl
index 16fe751f1..d90710df0 100755
--- a/scripts/dpkg-checkbuilddeps.pl
+++ b/scripts/dpkg-checkbuilddeps.pl
@@ -123,8 +123,9 @@ sub parse_status {
my $facts = Dpkg::Deps::KnownFacts->new();
local $/ = '';
- open(STATUS, '<', $status) || syserr(_g("cannot open %s"), $status);
- while (<STATUS>) {
+ open(my $status_fh, '<', $status) ||
+ syserr(_g("cannot open %s"), $status);
+ while (<$status_fh>) {
next unless /^Status: .*ok installed$/m;
my ($package) = /^Package: (.*)$/m;
@@ -146,7 +147,7 @@ sub parse_status {
}
}
}
- close STATUS;
+ close $status_fh;
return $facts;
}
diff --git a/scripts/dpkg-distaddfile.pl b/scripts/dpkg-distaddfile.pl
index b2f176154..1bc1901e5 100755
--- a/scripts/dpkg-distaddfile.pl
+++ b/scripts/dpkg-distaddfile.pl
@@ -83,19 +83,21 @@ sysopen($lockfh, "debian/control", O_WRONLY) ||
file_lock($lockfh, "debian/control");
$fileslistfile="./$fileslistfile" if $fileslistfile =~ m/^\s/;
-open(Y, '>', "$fileslistfile.new") || syserr(_g("open new files list file"));
-if (open(X, '<', $fileslistfile)) {
- while (<X>) {
+open(my $fileslistnew_fh, '>', "$fileslistfile.new") ||
+ syserr(_g("open new files list file"));
+if (open(my $fileslist_fh, '<', $fileslistfile)) {
+ while (<$fileslist_fh>) {
s/\n$//;
next if m/^(\S+) / && $1 eq $file;
- print(Y "$_\n") || syserr(_g("copy old entry to new files list file"));
+ print($fileslistnew_fh "$_\n") ||
+ syserr(_g("copy old entry to new files list file"));
}
} elsif ($! != ENOENT) {
syserr(_g("read old files list file"));
}
-print(Y "$file $section $priority\n")
+print($fileslistnew_fh "$file $section $priority\n")
|| syserr(_g("write new entry to new files list file"));
-close(Y) || syserr(_g("close new files list file"));
+close($fileslistnew_fh) || syserr(_g("close new files list file"));
rename("$fileslistfile.new", $fileslistfile) ||
syserr(_g("install new files list file"));
diff --git a/scripts/dpkg-genchanges.pl b/scripts/dpkg-genchanges.pl
index 8a4839522..e61c8c863 100755
--- a/scripts/dpkg-genchanges.pl
+++ b/scripts/dpkg-genchanges.pl
@@ -227,8 +227,9 @@ if (defined($prev_changelog) and
}
if (not is_sourceonly) {
- open(FL, "<", $fileslistfile) || syserr(_g("cannot read files list file"));
- while(<FL>) {
+ open(my $fileslist_fh, "<", $fileslistfile) ||
+ syserr(_g("cannot read files list file"));
+ while(<$fileslist_fh>) {
if (m/^(([-+.0-9a-z]+)_([^_]+)_([-\w]+)\.u?deb) (\S+) (\S+)$/) {
defined($p2f{"$2 $4"}) &&
warning(_g("duplicate files list entry for package %s (line %d)"),
@@ -262,7 +263,7 @@ if (not is_sourceonly) {
error(_g("badly formed line in files list file, line %d"), $.);
}
}
- close(FL);
+ close($fileslist_fh);
}
# Scan control info of source package
@@ -344,9 +345,10 @@ foreach $_ (keys %{$changelog}) {
}
if ($changesdescription) {
- open(X, "<", $changesdescription) || syserr(_g("read changesdescription"));
- $fields->{'Changes'} = "\n" . join("", <X>);
- close(X);
+ open(my $changes_fh, "<", $changesdescription) ||
+ syserr(_g("read changesdescription"));
+ $fields->{'Changes'} = "\n" . join("", <$changes_fh>);
+ close($changes_fh);
}
for my $pa (keys %pa2f) {
diff --git a/scripts/dpkg-gencontrol.pl b/scripts/dpkg-gencontrol.pl
index cabd242f6..bb2204071 100755
--- a/scripts/dpkg-gencontrol.pl
+++ b/scripts/dpkg-gencontrol.pl
@@ -318,7 +318,8 @@ if ($oppackage ne $sourcepackage || $verdiff) {
}
if (!defined($substvars->get('Installed-Size'))) {
- defined(my $c = open(DU, "-|")) || syserr(_g("cannot fork for %s"), "du");
+ my $du_fh;
+ defined(my $c = open($du_fh, "-|")) || syserr(_g("cannot fork for %s"), "du");
if (!$c) {
chdir("$packagebuilddir") ||
syserr(_g("chdir for du to \`%s'"), $packagebuilddir);
@@ -326,10 +327,10 @@ if (!defined($substvars->get('Installed-Size'))) {
syserr(_g("unable to execute %s"), "du");
}
my $duo = '';
- while (<DU>) {
+ while (<$du_fh>) {
$duo .= $_;
}
- close(DU);
+ close($du_fh);
$? && subprocerr(_g("du in \`%s'"), $packagebuilddir);
$duo =~ m/^(\d+)\s+\.$/ ||
error(_g("du gave unexpected output \`%s'"), $duo);
@@ -358,20 +359,22 @@ sysopen($lockfh, "debian/control", O_WRONLY) ||
file_lock($lockfh, "debian/control");
$fileslistfile="./$fileslistfile" if $fileslistfile =~ m/^\s/;
-open(Y, ">", "$fileslistfile.new") || syserr(_g("open new files list file"));
-binmode(Y);
-if (open(X, "<", $fileslistfile)) {
- binmode(X);
- while (<X>) {
+open(my $fileslistnew_fh, ">", "$fileslistfile.new") ||
+ syserr(_g("open new files list file"));
+binmode($fileslistnew_fh);
+if (open(my $fileslist_fh, "<", $fileslistfile)) {
+ binmode($fileslist_fh);
+ while (<$fileslist_fh>) {
chomp;
next if m/^([-+0-9a-z.]+)_[^_]+_([\w-]+)\.(a-z+) /
&& ($1 eq $oppackage)
&& ($3 eq $pkg_type)
&& (debarch_eq($2, $fields->{'Architecture'} || "")
|| debarch_eq($2, 'all'));
- print(Y "$_\n") || syserr(_g("copy old entry to new files list file"));
+ print($fileslistnew_fh "$_\n") ||
+ syserr(_g("copy old entry to new files list file"));
}
- close(X) || syserr(_g("close old files list file"));
+ close($fileslist_fh) || syserr(_g("close old files list file"));
} elsif ($! != ENOENT) {
syserr(_g("read old files list file"));
}
@@ -380,11 +383,12 @@ $sversion =~ s/^\d+://;
$forcefilename = sprintf("%s_%s_%s.%s", $oppackage, $sversion,
$fields->{'Architecture'} || "", $pkg_type)
unless ($forcefilename);
-print(Y $substvars->substvars(sprintf("%s %s %s\n", $forcefilename,
- $fields->{'Section'} || '-',
- $fields->{'Priority'} || '-')))
+print($fileslistnew_fh $substvars->substvars(sprintf("%s %s %s\n",
+ $forcefilename,
+ $fields->{'Section'} || '-',
+ $fields->{'Priority'} || '-')))
|| syserr(_g("write new entry to new files list file"));
-close(Y) || syserr(_g("close new files list file"));
+close($fileslistnew_fh) || syserr(_g("close new files list file"));
rename("$fileslistfile.new", $fileslistfile) || syserr(_g("install new files list file"));
# Release the lock
diff --git a/scripts/dpkg-gensymbols.pl b/scripts/dpkg-gensymbols.pl
index 3d29a934e..f2cacc223 100755
--- a/scripts/dpkg-gensymbols.pl
+++ b/scripts/dpkg-gensymbols.pl
@@ -193,13 +193,13 @@ if (not scalar @files) {
not check_files_are_the_same($packagebuilddir, $updir)) {
next PATH if -l $updir;
}
- opendir(DIR, "$libdir") ||
+ opendir(my $libdir_dh, "$libdir") ||
syserr(_g("Can't read directory %s: %s"), $libdir, $!);
push @files, grep {
/(\.so\.|\.so$)/ && -f $_ &&
Dpkg::Shlibs::Objdump::is_elf($_);
- } map { "$libdir/$_" } readdir(DIR);
- close(DIR);
+ } map { "$libdir/$_" } readdir($libdir_dh);
+ close($libdir_dh);
}
}
diff --git a/scripts/dpkg-mergechangelogs.pl b/scripts/dpkg-mergechangelogs.pl
index c19de08f3..d6a5d871c 100755
--- a/scripts/dpkg-mergechangelogs.pl
+++ b/scripts/dpkg-mergechangelogs.pl
@@ -125,9 +125,9 @@ while (1) {
}
if (defined($out_file) and $out_file ne "-") {
- open(OUT, ">", $out_file) || syserr(_g("cannot write %s"), $out_file);
- print OUT ((blessed $_) ? "$_" : "$_\n") foreach @result;
- close(OUT) || syserr(_g("cannot write %s"), $out_file);
+ open(my $out_fh, ">", $out_file) || syserr(_g("cannot write %s"), $out_file);
+ print $out_fh ((blessed $_) ? "$_" : "$_\n") foreach @result;
+ close($out_fh) || syserr(_g("cannot write %s"), $out_file);
} else {
print ((blessed $_) ? "$_" : "$_\n") foreach @result;
}
diff --git a/scripts/dpkg-name.pl b/scripts/dpkg-name.pl
index 6edc03247..85d95ec2a 100755
--- a/scripts/dpkg-name.pl
+++ b/scripts/dpkg-name.pl
@@ -92,11 +92,11 @@ sub getfields($)
my ($filename) = @_;
# Read the fields
- open(CDATA, '-|', "dpkg-deb", "-f", "--", $filename) ||
+ open(my $cdata_fh, '-|', "dpkg-deb", "-f", "--", $filename) ||
syserr(_g("cannot open %s"), $filename);
my $fields = Dpkg::Control->new(type => CTRL_PKG_DEB);
- $fields->parse(\*CDATA, sprintf(_g("binary control file %s"), $filename));
- close(CDATA);
+ $fields->parse($cdata_fh, sprintf(_g("binary control file %s"), $filename));
+ close($cdata_fh);
return $fields;
}
diff --git a/scripts/dpkg-scansources.pl b/scripts/dpkg-scansources.pl
index e67f50c85..056b53267 100755
--- a/scripts/dpkg-scansources.pl
+++ b/scripts/dpkg-scansources.pl
@@ -309,9 +309,9 @@ sub main {
load_src_override $Src_override, $override;
load_override_extra $Extra_override_file if defined $Extra_override_file;
- open FIND, '-|', "find -L \Q$dir\E -name '*.dsc' -print"
+ open my $find_fh, '-|', "find -L \Q$dir\E -name '*.dsc' -print"
or syserr(_g("cannot fork for %s"), "find");
- while (<FIND>) {
+ while (<$find_fh>) {
chomp;
s-^\./+--;
@@ -334,7 +334,7 @@ sub main {
push @out, $fields;
}
}
- close FIND or error(close_msg, 'find');
+ close $find_fh or error(close_msg, 'find');
if (@out) {
map {
diff --git a/scripts/dpkg-shlibdeps.pl b/scripts/dpkg-shlibdeps.pl
index 3df57549d..bc258dcd7 100755
--- a/scripts/dpkg-shlibdeps.pl
+++ b/scripts/dpkg-shlibdeps.pl
@@ -450,19 +450,19 @@ my $fh;
if ($stdout) {
$fh = \*STDOUT;
} else {
- open(NEW, ">", "$varlistfile.new") ||
+ open(my $new_fh, ">", "$varlistfile.new") ||
syserr(_g("open new substvars file \`%s'"), "$varlistfile.new");
if (-e $varlistfile) {
- open(OLD, "<", $varlistfile) ||
+ open(my $old_fh, "<", $varlistfile) ||
syserr(_g("open old varlist file \`%s' for reading"), $varlistfile);
- foreach my $entry (grep { not m/^\Q$varnameprefix\E:/ } (<OLD>)) {
- print(NEW $entry) ||
+ foreach my $entry (grep { not m/^\Q$varnameprefix\E:/ } (<$old_fh>)) {
+ print($new_fh $entry) ||
syserr(_g("copy old entry to new varlist file \`%s'"),
"$varlistfile.new");
}
- close(OLD);
+ close($old_fh);
}
- $fh = \*NEW;
+ $fh = $new_fh;
}
# Write out the shlibs substvars
@@ -682,10 +682,10 @@ sub extract_from_shlibs {
}
# Open shlibs file
$shlibfile = "./$shlibfile" if $shlibfile =~ m/^\s/;
- open(SHLIBS, "<", $shlibfile) ||
+ open(my $shlibs_fh, "<", $shlibfile) ||
syserr(_g("unable to open shared libs info file \`%s'"), $shlibfile);
my $dep;
- while (<SHLIBS>) {
+ while (<$shlibs_fh>) {
s/\s*\n$//;
next if m/^\#/;
if (!m/^\s*(?:(\S+):\s+)?(\S+)\s+(\S+)(?:\s+(\S.*\S))?\s*$/) {
@@ -709,7 +709,7 @@ sub extract_from_shlibs {
}
}
}
- close(SHLIBS);
+ close($shlibs_fh);
return $dep;
}
@@ -747,16 +747,16 @@ sub symfile_has_soname {
return $symfile_has_soname_cache{$file}{$soname};
}
- open(SYM_FILE, "<", $file) ||
+ open(my $symfile_fh, "<", $file) ||
syserr(_g("cannot open file %s"), $file);
my $result = 0;
- while (<SYM_FILE>) {
+ while (<$symfile_fh>) {
if (/^\Q$soname\E /) {
$result = 1;
last;
}
}
- close(SYM_FILE);
+ close($symfile_fh);
$symfile_has_soname_cache{$file}{$soname} = $result;
return $result;
}
@@ -834,7 +834,7 @@ sub find_packages {
}
return $pkgmatch unless scalar(@files);
- my $pid = open(DPKG, "-|");
+ my $pid = open(my $dpkg_fh, "-|");
syserr(_g("cannot fork for %s"), "dpkg --search") unless defined($pid);
if (!$pid) {
# Child process running dpkg --search and discarding errors
@@ -844,7 +844,7 @@ sub find_packages {
exec("dpkg", "--search", "--", @files)
|| syserr(_g("unable to execute %s"), "dpkg");
}
- while(defined($_ = <DPKG>)) {
+ while (defined($_ = <$dpkg_fh>)) {
chomp($_);
if (m/^local diversion |^diversion by/) {
warning(_g("diversions involved - output may be incorrect"));
@@ -856,6 +856,6 @@ sub find_packages {
warning(_g("unknown output from dpkg --search: '%s'"), $_);
}
}
- close(DPKG);
+ close($dpkg_fh);
return $pkgmatch;
}
diff --git a/scripts/dpkg-source.pl b/scripts/dpkg-source.pl
index 66153f2ae..d36254d6a 100755
--- a/scripts/dpkg-source.pl
+++ b/scripts/dpkg-source.pl
@@ -351,13 +351,13 @@ if ($options{'opmode'} =~ /^(-b|--print-format|--(before|after)-build|--commit)$
# Select the format to use
if (not defined $build_format) {
if (-e "$dir/debian/source/format") {
- open(FORMAT, "<", "$dir/debian/source/format") ||
+ open(my $format_fh, "<", "$dir/debian/source/format") ||
syserr(_g("cannot read %s"), "$dir/debian/source/format");
- $build_format = <FORMAT>;
+ $build_format = <$format_fh>;
chomp($build_format) if defined $build_format;
error(_g("%s is empty"), "$dir/debian/source/format")
unless defined $build_format and length $build_format;
- close(FORMAT);
+ close($format_fh);
} else {
warning(_g("no source format specified in %s, " .
"see dpkg-source(1)"), "debian/source/format")
diff --git a/scripts/t/600_Dpkg_Changelog.t b/scripts/t/600_Dpkg_Changelog.t
index 030de41e5..f9052d0f5 100644
--- a/scripts/t/600_Dpkg_Changelog.t
+++ b/scripts/t/600_Dpkg_Changelog.t
@@ -50,9 +50,9 @@ foreach my $file ("$datadir/countme", "$datadir/shadow", "$datadir/fields",
my $changes = Dpkg::Changelog::Debian->new(verbose => 0);
$changes->load($file);
- open(CLOG, "<", "$file") || die "Can't open $file\n";
- my $content = join("", <CLOG>);
- close(CLOG);
+ open(my $clog_fh, "<", "$file") || die "Can't open $file\n";
+ my $content = join("", <$clog_fh>);
+ close($clog_fh);
cmp_ok($content, 'eq', "$changes", "string output of Dpkg::Changelog on $file");
my $errors = $changes->get_parse_errors();
diff --git a/scripts/t/800_Dpkg_IPC.t b/scripts/t/800_Dpkg_IPC.t
index 52c8f586a..8c14f6d57 100644
--- a/scripts/t/800_Dpkg_IPC.t
+++ b/scripts/t/800_Dpkg_IPC.t
@@ -25,13 +25,14 @@ $/ = undef;
my ($tmp1_fh, $tmp1_name) = tempfile;
my ($tmp2_fh, $tmp2_name) = tempfile;
+my $tmp_fh;
my $string1 = "foo\nbar\n";
my $string2;
-open TMP, '>', $tmp1_name;
-print TMP $string1;
-close TMP;
+open $tmp_fh, '>', $tmp1_name;
+print $tmp_fh $string1;
+close $tmp_fh;
my $pid = spawn(exec => "cat",
from_string => \$string1,
@@ -49,9 +50,9 @@ ok($pid);
wait_child($pid);
-open TMP, '<', $tmp2_name;
-$string2 = <TMP>;
-close TMP;
+open $tmp_fh, '<', $tmp2_name;
+$string2 = <$tmp_fh>;
+close $tmp_fh;
is($string2, $string1, "{from,to}_handle");
@@ -63,9 +64,9 @@ $pid = spawn(exec => "cat",
ok($pid);
-open TMP, '<', $tmp2_name;
-$string2 = <TMP>;
-close TMP;
+open $tmp_fh, '<', $tmp2_name;
+$string2 = <$tmp_fh>;
+close $tmp_fh;
is($string2, $string1, "{from,to}_file");
diff --git a/scripts/t/850_Dpkg_Compression.t b/scripts/t/850_Dpkg_Compression.t
index 669729274..a4f99f0eb 100644
--- a/scripts/t/850_Dpkg_Compression.t
+++ b/scripts/t/850_Dpkg_Compression.t
@@ -52,17 +52,17 @@ sub test_write {
sub check_uncompressed {
my ($filename, $method) = @_;
- open(READ, "<", $filename) or die "cannot read $filename";
- my @read = <READ>;
- close READ or die "cannot close";
+ open(my $read_fh, "<", $filename) or die "cannot read $filename";
+ my @read = <$read_fh>;
+ close $read_fh or die "cannot close";
is_deeply(\@lines, \@read, "$filename correctly written ($method)");
}
sub check_compressed {
my ($filename, $method) = @_;
- open(READ, "-|", "zcat $tmpdir/myfile.gz") or die "cannot fork zcat";
- my @read = <READ>;
- close READ or die "cannot close";
+ open(my $read_fh, "-|", "zcat $tmpdir/myfile.gz") or die "cannot fork zcat";
+ my @read = <$read_fh>;
+ close $read_fh or die "cannot close";
is_deeply(\@lines, \@read, "$filename correctly written ($method)");
}
diff --git a/src/t/100_dpkg_divert.t b/src/t/100_dpkg_divert.t
index 114a1840f..311557c2f 100644
--- a/src/t/100_dpkg_divert.t
+++ b/src/t/100_dpkg_divert.t
@@ -48,21 +48,21 @@ sub cleanup {
sub install_diversions {
my ($txt) = @_;
- open(O, '>', "$admindir/diversions");
- print O $txt;
- close(O);
+ open(my $db_fh, '>', "$admindir/diversions");
+ print $db_fh $txt;
+ close($db_fh);
}
sub install_filelist {
my ($pkg, $arch, @files) = @_;
- open(L, '>', "$admindir/info/$pkg.list");
+ open(my $fileslist_fh, '>', "$admindir/info/$pkg.list");
for my $file (@files) {
- print L "$file\n";
+ print $fileslist_fh "$file\n";
}
- close(L);
+ close($fileslist_fh);
# Only installed packages have their files list considered.
- open(S, '>>', "$admindir/status");
- print S <<"EOF";
+ open(my $status_fh, '>>', "$admindir/status");
+ print $status_fh <<"EOF";
Package: $pkg
Status: install ok installed
Version: 0
@@ -71,7 +71,7 @@ Maintainer: dummy
Description: dummy
EOF
- close(S);
+ close($status_fh);
}
sub call {
@@ -134,9 +134,9 @@ sub diversions_pack {
sub diversions_eq {
my (@expected) = split /^/, shift;
- open(O, '<', "$admindir/diversions");
- my (@contents) = <O>;
- close(O);
+ open(my $db_fh, '<', "$admindir/diversions");
+ my (@contents) = <$db_fh>;
+ close($db_fh);
my (@expected_pack) = diversions_pack(@expected);
my (@contents_pack) = diversions_pack(@contents);
diff --git a/test/100_critic.t b/test/100_critic.t
index dee222610..fd62ad9cc 100644
--- a/test/100_critic.t
+++ b/test/100_critic.t
@@ -48,6 +48,7 @@ my @policies = qw(
ControlStructures::ProhibitLabelsWithSpecialBlockNames
ControlStructures::ProhibitUntilBlocks
Documentation::RequirePackageMatchesPodName
+ InputOutput::ProhibitBarewordFileHandles
InputOutput::ProhibitInteractiveTest
InputOutput::ProhibitOneArgSelect
InputOutput::ProhibitTwoArgOpen
diff --git a/utils/t/100_update_alternatives.t b/utils/t/100_update_alternatives.t
index 33f44eddd..69683a81d 100644
--- a/utils/t/100_update_alternatives.t
+++ b/utils/t/100_update_alternatives.t
@@ -257,9 +257,9 @@ check_choice(0, "auto", "initial install 3");
# verify that the administrative file is sorted properly
{
local $/ = undef;
- open(FILE, "<", "$admindir/generic-test") or die $!;
- my $content = <FILE>;
- close(FILE);
+ open(my $db_fh, "<", "$admindir/generic-test") or die $!;
+ my $content = <$db_fh>;
+ close($db_fh);
my $expected =
"auto