There is no need for the sort and print loop after the while loop. His input file is already sorted by frequency in descending order (your sample data would be sorted in descending order). So, the make_header() call and print routine could be done within the while loop.
Re^4: Sorting issue
Replies are listed 'Best First'.
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.