Perl::Critic::Policy::Community::LoopOnHash - Don't loop over hashes
It's possible to loop over a hash as if it was a list, which results in alternating between the keys and values of the hash. Often, the intent was instead to loop over either the keys or the values of the hash.
foreach my $foo (%hash) { ... } # not ok action() for %hash; # not ok foreach my $foo (keys %hash) { ... } # ok action() for values %hash; # ok
If you intended to loop over alternating keys and values, you can make this intent clear by first copying them to an array:
foreach my $key_or_value (@{[%hash]}) { ... } foreach my $key_or_value (my @dummy = %hash) { ... }
This policy is a subclass of the policy Perl::Critic::Policy::Variables::ProhibitLoopOnHash, and performs the same function but in the community theme.
community
This policy is part of Perl::Critic::Community.
This policy is not configurable except for the standard options.
Dan Book, dbook@cpan.org
dbook@cpan.org
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.
Perl::Critic
To install Perl::Critic::Community, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Perl::Critic::Community
CPAN shell
perl -MCPAN -e shell install Perl::Critic::Community
For more information on module installation, please visit the detailed CPAN module installation guide.