2 ms·
Let's not judge Perl in general by the author's Perl code, which starts with the baffling step of taking a reference to the argument array, then wraps it in a l
by JadeNB 12y ago
Let's not judge Perl in general by the author's Perl code, which starts with the baffling step of taking a reference to the argument array, then wraps it in a list and passes it to a function that immediately shifts it off the list and de-references it …. Also, as Veedrac pointed out (https://news.ycombinator.com/item?id=9562039 https://news.ycombinator.com/item?id=9562039), it carefully hashes the words by frequency, only to render the effort redundant by simply summing all the frequencies. (Your Python does the same, I assume for fidelity to the original.) A better Perl version might look like:
for my $file ( @ARGV ) {
my $words;
open my $fh, '<', $file or die;
local $/;
say "$file: ", scalar(split /\s+/, <$fh>), " words";
}
EDIT: Changed an explicit count of the `split` list into an implicit count via `scalar`.