Useless use of private variable in void context at...
(I should have made this explicit.) I certainly agree that either a while or a foreach loop would be preferable here. Unfortunately, neither of your suggested alternatives results in the same number of iterations as the original:
16:05 >perl -wE "my $c = 0; for (my $n = 3; $n >= 0; $n--) { ++$c; } s
+ay $c;"
4
16:05 >perl -wE "my $c = 0; my $n = 3; while ($n--) { ++$c; } say $c;"
3
16:05 >perl -wE "my $c = 0; my $n = 3; for (1 .. $n) { ++$c; } say $c;
+"
3
16:05 >
And since the loop is likely incomplete (see my comments regarding $outfile), we cannot be sure that $count won’t be used for something later on in the loop — in which case, the foreach version of the loop would provide the values in their reverse order. So the safest alternative is probably:
while ($count-- >= 0) {
Update 1: Except that the value of $count within this loop is always one less than its “proper” value.
Update 2: Upon reflection, I now realise that GrandFather’s alternative loops were not intended as equivalents to the original, but as corrections to it, since it’s most likely that the OP code meant to loop for exactly $count iterations. If so, I apologise to GrandFather for the misreading.
|