The input file was already sorted by frequency. I tried without the sort command. It didn't give me the sorted results. | [reply] |
That's because once you put the data in a hash, it's unordered, so 'keys' could return the keys in any order. What the previous poster is saying is that, if your lines are already sorted in the order you want the output, you could move the stuff from the sorted for loop up into your while loop, and just process the lines and print the results right there, one line at a time. No need to save it into a hash and then loop through the keys in that case. Just read a line, convert it, and print it.
| [reply] |