#!/usr/bin/env perl6
sub MAIN(*@filename) {
for @filename -> $file {
my $bag = $file.IO.slurp.words.Bag;
say "$file: { [+] $bag.values } words";
CATCH { default { say "Unable to count words in $file"; } }
}
}
The author did have a point he wanted to put across with the hash table - "Obviously, a frequency distribution was not necessary for just the counts, but I did want to highlight basic autovivification"
That doesn't feel like a good reason. The author could easily have come up with a better task (eg. count the number of words with more than one occurrence). This allows you to approach the problem in the optimal way in each language.