in reply to Re: Reporting entries in a file
in thread Reporting entries in a file
From what SkullOne said ("It's just a one-column file"), s/he had only one word per line, so the task is even easier (we need only to count the different types of line - maybe after stripping leading and trailing spaces). The concept of using a hash would be the same, but we don't need to split the line into words.
A solution which would do with arrays instead of hashes and is easy to code too, provided that we don't need stripping of the spaces, would be to slurp the whole file into a array, sort the array, and then (in a loop through the array), count the number of consecutive equal entries. This would get us an alphabetically sorted list of the words with associated count.
|
|---|