I recently came across the following code snippet
$count_stuff{$_}++ for @stuff;
It’s a pretty convenient way to use a hash to count occurrences of strings in an array for example. I understand how it works, but not why it works. I can not find the documentation for this way of using for.
Why does it work? And where is the documentation?
It is documented in the “perlsyn” man page, under Statement Modifiers (which talks about the postfix syntax) and under Foreach Loops (which explains that “for” and “foreach” are synonyms).