summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGuillem Jover <guillem@debian.org>2013-01-01 03:00:54 +0100
committerGuillem Jover <guillem@debian.org>2013-05-08 04:50:14 +0200
commit503c1e8a4689fe3c329a2ff1dd7f3c2db0d60d3f (patch)
tree11a3d5a752d4748791c2f5fbdb7aa6d1dc58f38a
parent5fb97d6dabbe6591527d338b71fb6cb2499447d9 (diff)
downloaddpkg-503c1e8a4689fe3c329a2ff1dd7f3c2db0d60d3f.tar.gz
perl: Use the .. operator instead of C-style for loops
Fixes ControlStructures::ProhibitCStyleForLoops. Warned-by: perlcritic
-rwxr-xr-xdselect/mkcurkeys.pl8
-rw-r--r--scripts/Dpkg/Shlibs/Symbol.pm2
-rw-r--r--scripts/Dpkg/Shlibs/SymbolFile.pm2
-rw-r--r--scripts/Dpkg/Source/Functions.pm10
-rw-r--r--scripts/t/190_Dpkg_Shlibs_Cppfilt.t4
-rw-r--r--src/t/100_dpkg_divert.t2
-rw-r--r--test/100_critic.t1
-rw-r--r--utils/t/100_update_alternatives.t4
8 files changed, 19 insertions, 14 deletions
diff --git a/dselect/mkcurkeys.pl b/dselect/mkcurkeys.pl
index d2f5783be..882fa1fc8 100755
--- a/dselect/mkcurkeys.pl
+++ b/dselect/mkcurkeys.pl
@@ -38,9 +38,11 @@ while (<$override_fh>) {
}
close($override_fh);
-for (my $i = 1, my $let = 'A'; $i <= 26; $i++, $let++) {
+my $let = 'A';
+for my $i (1 .. 26) {
$name{$i}= "^$let";
$base{$i}= '';
+ $let++;
}
our ($k, $v);
@@ -78,7 +80,7 @@ END
my ($comma);
-for (my $i = 33; $i <= 126; $i++) {
+for my $i (33 .. 126) {
$k= $i;
$v = pack('C', $i);
if ($v eq ',') { $comma=$k; next; }
@@ -100,7 +102,7 @@ for $k (sort {
p();
}
-for (my $i = 1; $i < 64; $i++) {
+for my $i (1 .. 63) {
$k= "KEY_F($i)"; $v= "F$i";
p();
}
diff --git a/scripts/Dpkg/Shlibs/Symbol.pm b/scripts/Dpkg/Shlibs/Symbol.pm
index ae53e43ce..ea767cfbf 100644
--- a/scripts/Dpkg/Shlibs/Symbol.pm
+++ b/scripts/Dpkg/Shlibs/Symbol.pm
@@ -265,7 +265,7 @@ sub equals {
if ($opts{tags}) {
return 0 if scalar(@{$self->{tagorder}}) != scalar(@{$other->{tagorder}});
- for (my $i = 0; $i < scalar(@{$self->{tagorder}}); $i++) {
+ for my $i (0 .. scalar(@{$self->{tagorder}}) - 1) {
my $tag = $self->{tagorder}->[$i];
return 0 if $tag ne $other->{tagorder}->[$i];
if (defined $self->{tags}{$tag} && defined $other->{tags}{$tag}) {
diff --git a/scripts/Dpkg/Shlibs/SymbolFile.pm b/scripts/Dpkg/Shlibs/SymbolFile.pm
index 6328f4b0f..9a4fac0cd 100644
--- a/scripts/Dpkg/Shlibs/SymbolFile.pm
+++ b/scripts/Dpkg/Shlibs/SymbolFile.pm
@@ -60,7 +60,7 @@ my %blacklist = (
_SDA_BASE_ => 1, # powerpc
);
-for (my $i = 14; $i <= 31; $i++) {
+for my $i (14 .. 31) {
# Many powerpc specific symbols
$blacklist{"_restfpr_$i"} = 1;
$blacklist{"_restfpr_$i\_x"} = 1;
diff --git a/scripts/Dpkg/Source/Functions.pm b/scripts/Dpkg/Source/Functions.pm
index d830b0b5f..dcb23af98 100644
--- a/scripts/Dpkg/Source/Functions.pm
+++ b/scripts/Dpkg/Source/Functions.pm
@@ -44,7 +44,7 @@ sub erasedir {
sub fixperms {
my ($dir) = @_;
- my ($mode, $modes_set, $i, $j);
+ my ($mode, $modes_set);
# Unfortunately tar insists on applying our umask _to the original
# permissions_ rather than mostly-ignoring the original
# permissions. We fix it up with chmod -R (which saves us some
@@ -52,11 +52,11 @@ sub fixperms {
# of a palaver. (Numeric doesn't work because we need [ugo]+X
# and [ugo]=<stuff> doesn't work because that unsets sgid on dirs.)
$mode = 0777 & ~umask;
- for ($i = 0; $i < 9; $i += 3) {
+ for my $i (0 .. 2) {
$modes_set .= ',' if $i;
- $modes_set .= qw(u g o)[$i/3];
- for ($j = 0; $j < 3; $j++) {
- $modes_set .= $mode & (0400 >> ($i+$j)) ? '+' : '-';
+ $modes_set .= qw(u g o)[$i];
+ for my $j (0 .. 2) {
+ $modes_set .= $mode & (0400 >> ($i * 3 + $j)) ? '+' : '-';
$modes_set .= qw(r w X)[$j];
}
}
diff --git a/scripts/t/190_Dpkg_Shlibs_Cppfilt.t b/scripts/t/190_Dpkg_Shlibs_Cppfilt.t
index acacf153a..1bda4a5a0 100644
--- a/scripts/t/190_Dpkg_Shlibs_Cppfilt.t
+++ b/scripts/t/190_Dpkg_Shlibs_Cppfilt.t
@@ -77,8 +77,8 @@ my @demangledtext = split(/\n+/s, <<'END');
00000000002f6160 w DO .data.rel.ro 0000000000000050 VTT for std::basic_stringstream<char, std::char_traits<char>, std::allocator<char> >@GLIBCXX_3.4
END
-for (my $try = 1; $try <= 7; $try++) {
- for (my $i = 0; $i <= $#mangledtext; $i++) {
+for my $try (1 .. 7) {
+ for my $i (0 .. $#mangledtext) {
my $demangled = cppfilt_demangle_cpp($mangledtext[$i]) || $mangledtext[$i];
is($demangled, $demangledtext[$i], "mass c++ demangling (${try}x" . (${i} + 1) . ')');
}
diff --git a/src/t/100_dpkg_divert.t b/src/t/100_dpkg_divert.t
index 5b976a78b..40af7a9f8 100644
--- a/src/t/100_dpkg_divert.t
+++ b/src/t/100_dpkg_divert.t
@@ -125,9 +125,11 @@ sub diversions_pack {
my (@data) = @_;
my @data_packed;
+ ## no critic (ControlStructures::ProhibitCStyleForLoops)
for (my ($i) = 0; $i < $#data; $i += 3) {
push @data_packed, [ @data[$i .. $i + 2] ];
}
+ ## use critic
my @list = sort { $a->[0] cmp $b->[0] } @data_packed;
return @list;
diff --git a/test/100_critic.t b/test/100_critic.t
index bf50cd8b2..f064e5ed1 100644
--- a/test/100_critic.t
+++ b/test/100_critic.t
@@ -46,6 +46,7 @@ my @policies = qw(
ClassHierarchies::ProhibitOneArgBless
CodeLayout::ProhibitQuotedWordLists
CodeLayout::RequireConsistentNewlines
+ ControlStructures::ProhibitCStyleForLoops
ControlStructures::ProhibitLabelsWithSpecialBlockNames
ControlStructures::ProhibitUntilBlocks
Documentation::RequirePackageMatchesPodName
diff --git a/utils/t/100_update_alternatives.t b/utils/t/100_update_alternatives.t
index 1a46e3d65..6df050452 100644
--- a/utils/t/100_update_alternatives.t
+++ b/utils/t/100_update_alternatives.t
@@ -175,7 +175,7 @@ sub get_slaves_status {
my %slaves;
# None of the slaves are installed
foreach my $alt (@choices) {
- for(my $i = 0; $i < @{$alt->{slaves}}; $i++) {
+ for my $i (0 .. @{$alt->{slaves}} - 1) {
$slaves{$alt->{slaves}[$i]{name}} = $alt->{slaves}[$i];
$slaves{$alt->{slaves}[$i]{name}}{installed} = 0;
}
@@ -183,7 +183,7 @@ sub get_slaves_status {
# except those of the current alternative (minus optional slaves)
if (defined($id)) {
my $alt = $choices[$id];
- for(my $i = 0; $i < @{$alt->{slaves}}; $i++) {
+ for my $i (0 .. @{$alt->{slaves}} - 1) {
$slaves{$alt->{slaves}[$i]{name}} = $alt->{slaves}[$i];
if (-e $alt->{slaves}[$i]{path}) {
$slaves{$alt->{slaves}[$i]{name}}{installed} = 1;