Ver código fonte

perl: Use the .. operator instead of C-style for loops

Fixes ControlStructures::ProhibitCStyleForLoops.

Warned-by: perlcritic
Guillem Jover 13 anos atrás
pai
commit
503c1e8a46

+ 5 - 3
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();
 }

+ 1 - 1
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}) {

+ 1 - 1
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;

+ 5 - 5
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];
         }
     }

+ 2 - 2
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) . ')');
     }

+ 2 - 0
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;

+ 1 - 0
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

+ 2 - 2
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;