Commit 3da27157316cbcce326d56faa0a7a5cadc7ae507
Committed by
Michal Marek
1 parent
1f2a144f5a
Exists in
master
and in
20 other branches
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>
Showing 1 changed file with 14 additions and 10 deletions Side-by-side Diff
scripts/checkincludes.pl
... | ... | @@ -11,6 +11,8 @@ |
11 | 11 | # you do have real dups and do not have them under #ifdef's. You |
12 | 12 | # could also just review the results. |
13 | 13 | |
14 | +use strict; | |
15 | + | |
14 | 16 | sub usage { |
15 | 17 | print "Usage: checkincludes.pl [-r]\n"; |
16 | 18 | print "By default we just warn of duplicates\n"; |
17 | 19 | |
18 | 20 | |
19 | 21 | |
... | ... | @@ -35,23 +37,24 @@ |
35 | 37 | } |
36 | 38 | } |
37 | 39 | |
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"; | |
40 | 43 | |
41 | 44 | my %includedfiles = (); |
42 | 45 | my @file_lines = (); |
43 | 46 | |
44 | - while (<FILE>) { | |
47 | + while (<$f>) { | |
45 | 48 | if (m/^\s*#\s*include\s*[<"](\S*)[>"]/o) { |
46 | 49 | ++$includedfiles{$1}; |
47 | 50 | } |
48 | 51 | push(@file_lines, $_); |
49 | 52 | } |
50 | 53 | |
51 | - close(FILE); | |
54 | + close($f); | |
52 | 55 | |
53 | 56 | if (!$remove) { |
54 | - foreach $filename (keys %includedfiles) { | |
57 | + foreach my $filename (keys %includedfiles) { | |
55 | 58 | if ($includedfiles{$filename} > 1) { |
56 | 59 | print "$file: $filename is included more than once.\n"; |
57 | 60 | } |
58 | 61 | |
59 | 62 | |
60 | 63 | |
61 | 64 | |
... | ... | @@ -59,28 +62,29 @@ |
59 | 62 | next; |
60 | 63 | } |
61 | 64 | |
62 | - open(FILE,">$file") || die("Cannot write to $file: $!"); | |
65 | + open($f, '>', $file) | |
66 | + or die("Cannot write to $file: $!"); | |
63 | 67 | |
64 | 68 | my $dups = 0; |
65 | 69 | foreach (@file_lines) { |
66 | 70 | if (m/^\s*#\s*include\s*[<"](\S*)[>"]/o) { |
67 | - foreach $filename (keys %includedfiles) { | |
71 | + foreach my $filename (keys %includedfiles) { | |
68 | 72 | if ($1 eq $filename) { |
69 | 73 | if ($includedfiles{$filename} > 1) { |
70 | 74 | $includedfiles{$filename}--; |
71 | 75 | $dups++; |
72 | 76 | } else { |
73 | - print FILE $_; | |
77 | + print {$f} $_; | |
74 | 78 | } |
75 | 79 | } |
76 | 80 | } |
77 | 81 | } else { |
78 | - print FILE $_; | |
82 | + print {$f} $_; | |
79 | 83 | } |
80 | 84 | } |
81 | 85 | if ($dups > 0) { |
82 | 86 | print "$file: removed $dups duplicate includes\n"; |
83 | 87 | } |
84 | - close(FILE); | |
88 | + close($f); | |
85 | 89 | } |