-
-
22 Apr 2019 13:45:16 UTC
- Distribution: Perl-Critic-Policy-Variables-ProhibitLoopOnHash
- Module version: 0.008
- Source (raw)
- Browse (raw)
- Changes
- How to Contribute
- Repository
- Issues (0)
- Testers (2067 / 0 / 0)
- Kwalitee
Bus factor: 1- 93.92% Coverage
- License: perl_5
- Activity
24 month- Tools
- Download (14.08KB)
- MetaCPAN Explorer
- Permissions
- Subscribe to distribution
- Permalinks
- This version
- Latest version
NAME
Perl::Critic::Policy::Variables::ProhibitLoopOnHash - Don't write loops on hashes, only on keys and values of hashes
VERSION
version 0.008
DESCRIPTION
When "looping over hashes," we mean looping over hash keys or hash values. If you forgot to call
keys
orvalues
you will accidentally loop over both.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 %{ $hash{'stuff'} } ? keys %{ $hash{'stuff'} } : (); # ok
(Granted, the second example there doesn't make much sense, but I have found a variation of it in real code.)
CONFIGURATION
This policy is not configurable except for the standard options.
AUTHOR
Sawyer X,
xsawyerx@cpan.org
THANKS
Thank you to Ruud H.G. Van Tol.
SEE ALSO
AUTHOR
Sawyer X
COPYRIGHT AND LICENSE
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.
Module Install Instructions
To install Perl::Critic::Policy::Variables::ProhibitLoopOnHash, copy and paste the appropriate command in to your terminal.
cpanm Perl::Critic::Policy::Variables::ProhibitLoopOnHash
perl -MCPAN -e shell install Perl::Critic::Policy::Variables::ProhibitLoopOnHash
For more information on module installation, please visit the detailed CPAN module installation guide.