Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/xsawyerx/perl-critic-policy-variables-prohibitlooponhash
Perl::Critic::Policy::Variables::ProhibitLoopOnHash - Don't write loops on hashes, only on keys and values of hashes
https://github.com/xsawyerx/perl-critic-policy-variables-prohibitlooponhash
Last synced: 28 days ago
JSON representation
Perl::Critic::Policy::Variables::ProhibitLoopOnHash - Don't write loops on hashes, only on keys and values of hashes
- Host: GitHub
- URL: https://github.com/xsawyerx/perl-critic-policy-variables-prohibitlooponhash
- Owner: xsawyerx
- Created: 2018-03-08T15:35:24.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2022-10-27T15:45:46.000Z (about 2 years ago)
- Last Synced: 2024-10-13T11:37:13.489Z (about 1 month ago)
- Language: Perl
- Size: 21.5 KB
- Stars: 1
- Watchers: 2
- Forks: 3
- Open Issues: 1
-
Metadata Files:
- Readme: README.mkdn
- Changelog: Changes
Awesome Lists containing this project
README
# 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` or `values` 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; # okAn 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, `[email protected]`
# THANKS
Thank you to Ruud H.G. Van Tol.
# SEE ALSO
[Perl::Critic](https://metacpan.org/pod/Perl::Critic)
# 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.