Perl::Critic::Policy::Variables::ProhibitLoopOnHash - Don't write loops on hashes, only on keys and values of hashes
version 0.002
When "looping over hashes," we mean looping over hash keys or hash values. If you forgot to call keys or values you will accidentally loop over both.
keys
values
foreach my $foo (%hash) {...} # not ok action() for %hash; # not ok foreach my $foo ( keys %hash ) {...} # ok action() for values %hash; # ok
An effort is made to detect expressions:
action() for %hash ? keys %hash : (); # ok action() for %{ keys $hash{'stuff'} ? $hash{'stuff'} : {} }; # ok
This policy is not configurable except for the standard options.
Sawyer X, xsaawyerx@cpan.org
xsaawyerx@cpan.org
Thank you to Ruud H.G. Van Tol.
Perl::Critic
Sawyer X
This software is copyright (c) 2018 by Sawyer X.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
To install Perl::Critic::Policy::Variables::ProhibitLoopOnHash, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Perl::Critic::Policy::Variables::ProhibitLoopOnHash
CPAN shell
perl -MCPAN -e shell install Perl::Critic::Policy::Variables::ProhibitLoopOnHash
For more information on module installation, please visit the detailed CPAN module installation guide.