4 ms·
> Perl 5, perhaps surprisingly, is not simpler: Here's one. perl -0777 -nE '$w{$_}++ for split; say for (sort {$w{$b} <=> $w{$a}} keys %w)[0..9]' It is s
by prakashk 13y ago
> Perl 5, perhaps surprisingly, is not simpler:
Here's one.
perl -0777 -nE '$w{$_}++ for split; say for (sort {$w{$b} <=> $w{$a}} keys %w)[0..9]'
It is slightly different compared to your version in that each word is printed on a separate line. To print all words on the same line, is just a bit longer:
perl -0777 -nE '$w{$_}++ for split; $, = $"; say((sort {$w{$b} <=> $w{$a}} keys %w)[0..9])'