Skip to content

Commit 3da2715

Browse files
Stephen Hemmingermichal42
authored andcommitted
checkincludes: fix perlcritic warnings
Turn on strict checking. Use local file handles. Use three argument open. Signed-off-by: Stephen Hemminger <shemminger@vyatta.com> Cc: Cong Wang <amwang@redhat.com> Cc: Michal Marek <mmarek@suse.cz> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Michal Marek <mmarek@suse.cz>
1 parent 1f2a144 commit 3da2715

1 file changed

Lines changed: 14 additions & 10 deletions

File tree

scripts/checkincludes.pl

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
# you do have real dups and do not have them under #ifdef's. You
1212
# could also just review the results.
1313

14+
use strict;
15+
1416
sub usage {
1517
print "Usage: checkincludes.pl [-r]\n";
1618
print "By default we just warn of duplicates\n";
@@ -35,51 +37,53 @@ sub usage {
3537
}
3638
}
3739

38-
foreach $file (@ARGV) {
39-
open(FILE, $file) or die "Cannot open $file: $!.\n";
40+
foreach my $file (@ARGV) {
41+
open(my $f, '<', $file)
42+
or die "Cannot open $file: $!.\n";
4043

4144
my %includedfiles = ();
4245
my @file_lines = ();
4346

44-
while (<FILE>) {
47+
while (<$f>) {
4548
if (m/^\s*#\s*include\s*[<"](\S*)[>"]/o) {
4649
++$includedfiles{$1};
4750
}
4851
push(@file_lines, $_);
4952
}
5053

51-
close(FILE);
54+
close($f);
5255

5356
if (!$remove) {
54-
foreach $filename (keys %includedfiles) {
57+
foreach my $filename (keys %includedfiles) {
5558
if ($includedfiles{$filename} > 1) {
5659
print "$file: $filename is included more than once.\n";
5760
}
5861
}
5962
next;
6063
}
6164

62-
open(FILE,">$file") || die("Cannot write to $file: $!");
65+
open($f, '>', $file)
66+
or die("Cannot write to $file: $!");
6367

6468
my $dups = 0;
6569
foreach (@file_lines) {
6670
if (m/^\s*#\s*include\s*[<"](\S*)[>"]/o) {
67-
foreach $filename (keys %includedfiles) {
71+
foreach my $filename (keys %includedfiles) {
6872
if ($1 eq $filename) {
6973
if ($includedfiles{$filename} > 1) {
7074
$includedfiles{$filename}--;
7175
$dups++;
7276
} else {
73-
print FILE $_;
77+
print {$f} $_;
7478
}
7579
}
7680
}
7781
} else {
78-
print FILE $_;
82+
print {$f} $_;
7983
}
8084
}
8185
if ($dups > 0) {
8286
print "$file: removed $dups duplicate includes\n";
8387
}
84-
close(FILE);
88+
close($f);
8589
}

0 commit comments

Comments
 (0)