Yet another solution to word counting problem in Perl!
Jun 21, 2013
Today I found a post about word counting problem. While I hadn’t been impressed in suggested solutions, and I’ve known before that awk & sed solution would be the smallest and the simplest one, I decided to write my own solution to this problem in Perl!.
I stand on opinion that Perl! in some cases could be useful, because it has some good pipingflags like file processing flag, inline editing. Perl! also has some good special variables like @, $, $1, $2 and etcetera.
Unfortunately, my solution doesn’t look pretty enough and I think it can be improved somehow, but I think it can show some powerful sides o programming on Perl!.
If you hadn’t read the whole text above, here is the task :
Read a file of text, determine the n most frequently used words, and print out a sorted list of those words along with their frequencies.
And my solution
Possible result for the first volume of ‘War and Peace’ book by Leo Tolstoy :
PS. Thanks, I know about ‘strict’ mode and warnings.