Package Info

perl-Perl-Critic-Policy-Variables-ProhibitLoopOnHash


Don't write loops on hashes, only on keys and values of hashes


Development/Libraries/Perl

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;           # ok

An effort is made to detect expressions:

action() for %hash ? keys %hash : ();                             # ok
action() for % ? keys % : (); # ok

(Granted, the second example there doesn't make much sense, but I have found a variation of it in real code.)


License: Artistic-1.0 OR GPL-1.0-or-later
URL: https://metacpan.org/release/Perl-Critic-Policy-Variables-ProhibitLoopOnHash

Categories

Releases

Package Version Update ID Released Package Hub Version Platforms Subpackages
0.008-bp156.3.1 info GA Release 2023-07-22 15 SP6
  • AArch64
  • ppc64le
  • s390x
  • x86-64
  • perl-Perl-Critic-Policy-Variables-ProhibitLoopOnHash
0.008-bp155.2.8 info GA Release 2023-05-17 15 SP5
  • AArch64
  • ppc64le
  • s390x
  • x86-64
  • perl-Perl-Critic-Policy-Variables-ProhibitLoopOnHash
0.008-bp154.1.17 info GA Release 2022-05-09 15 SP4
  • AArch64
  • ppc64le
  • s390x
  • x86-64
  • perl-Perl-Critic-Policy-Variables-ProhibitLoopOnHash
0.008-bp153.1.12 info GA Release 2021-03-06 15 SP3
  • AArch64
  • ppc64le
  • s390x
  • x86-64
  • perl-Perl-Critic-Policy-Variables-ProhibitLoopOnHash
0.008-bp152.1.10 info GA Release 2020-04-17 15 SP2
  • AArch64
  • ppc64le
  • s390x
  • x86-64
  • perl-Perl-Critic-Policy-Variables-ProhibitLoopOnHash