table of contents
Perl::Critic::Policy::Freenode::LoopOnHash(3pm) | User Contributed Perl Documentation | Perl::Critic::Policy::Freenode::LoopOnHash(3pm) |
NAME¶
Perl::Critic::Policy::Freenode::LoopOnHash - Don't loop over hashesDESCRIPTION¶
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 "freenode" theme.
AFFILIATION¶
This policy is part of Perl::Critic::Freenode.CONFIGURATION¶
This policy is not configurable except for the standard options.AUTHOR¶
Dan Book, "dbook@cpan.org"COPYRIGHT AND LICENSE¶
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.
SEE ALSO¶
Perl::Critic2018-12-21 | perl v5.28.1 |