NAME
Perl::Critic::Policy::Freenode::WhileDiamondDefaultAssignment - Don't use while with implicit assignment to $_
DESCRIPTION
The diamond operator <>
is extra magical in a while condition: if it is the only thing in the condition, it will assign its result to $_
, but it does not localize $_
to the while loop. (Note, this also applies to a for (;<>;)
construct.) This can unintentionally confuse outer loops that are already using $_
to iterate. To avoid this possibility, assign the result of the diamond operator to an explicit lexical variable.
while (<$fh>) { ... } # not ok
... while <STDIN>; # not ok
for (;<>;) { ... } # not ok
while (my $line = <$fh>) { ... } # ok
... while $line = <STDIN>; # ok
for (;my $line = <>;) { ... } # ok
AFFILIATION
This policy is part of Perl::Critic::Freenode.
CONFIGURATION
This policy is not configurable except for the standard options.
AUTHOR
Dan Book, dbook@cpan.org
COPYRIGHT AND LICENSE
Copyright 2015, Dan Book.
This library is free software; you may redistribute it and/or modify it under the terms of the Artistic License version 2.0.