Perl::...pOnHash(3pm)

πŸ’… NAME πŸ’…

Perl::Critic::Policy::Variables::ProhibitLoopOnHash β€” bestie, do NOT write loops on hashes. Only on keys and values of hashes. That's it, that's the whole vibe. πŸŽ€

(you'll also see it hanging out in the Perl::...pOnHash(3pm) manpage, iykyk)


✨ VERSION ✨

version 0.009 πŸ¦‹


🌸 DESCRIPTION 🌸

okay so when we say "looping over hashes," we mean looping over hash keys or hash values. That's the intended thing. The moment you forget to call keys or values, you don't loop over one or the other β€” you accidentally loop over BOTH. not me making that mistake 😭 it's giving chaos.

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 like these:

action() for %hash ? keys %hash : ();                             # ok
action() for %{ $hash{'stuff'} } ? keys %{ $hash{'stuff'} } : (); # ok

(Granted, that second example is lowkey nonsense β€” it doesn't make much sense, fr fr β€” but the author has found a variation of it in real code. so. here we are. πŸ™ˆ)


πŸŽ€ CONFIGURATION πŸŽ€

This policy is not configurable except for the standard options. That's the whole menu, bestie. no secret extras. πŸ’…


πŸ‘‘ AUTHOR πŸ‘‘

Sawyer X, "xsawyerx@cpan.org" 🫢


🌈 THANKS 🌈

Thank you to Ruud H.G. Van Tol. πŸ“ absolute icon behaviour, we love to see it.


⭐ SEE ALSO ⭐

Perl::Critic 🧚


πŸ’– AUTHOR πŸ’–

Sawyer X ✨


This software is Copyright (c) 2026 by Sawyer X.

This is free software, licensed under:

The MIT (X11) License

k that's the whole page bestie, go forth and always write keys or values, mwah πŸ’œ

signing off from the perl v5.40.1 era, dated 2026-01-23, on the Perl::...pOnHash(3pm) page πŸ¦‹ slay, periodt πŸ’…

πŸ“¦ where this page comes from