NAME
Perl::Critic::Policy::Variables::ProhibitTopicIterator - Use named loop control variables.
DESCRIPTION
Loops with no named variable become a maintenance concern as the loop complexity grows. Larger, multi-line, and nested loops can lead to programmer confusion about the true meaning of $_
. To ensure long-term maintainability of code, named variables are recommended for all loops.
This policy considers any loop control without a named variable to be a violation.
Moreover, if/while statements that assign directly to $_
are considered a violation.
foreach my $i (1..3) { ... } # ok
for(my $i=1;$i<=3;$i++) { ... } # ok
for my $i (1..3) { ... } # ok
if(my $i=shift(@A)) { ... } # ok
while(my $i=shift(@A)) { ... } # ok
foreach (1..3) { ... } # not ok
for($_=1;$_<=3;$_++) { ... } # not ok
for (1..3) { ... } # not ok
if($_=shift(@A)) { ... } # not ok
while($_=shift(@A)) { ... } # not ok
CONFIGURATION
None at this time, but future configuration may make the policy less aggressive about certain constructions.
NOTES
Post-conditionals can be enforced with Perl::Critic::Policy::ControlStructures::ProhibitPostfixControls.