Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery

Re^4: Sorting issue

by Cristoforo (Curate)
on Nov 05, 2011 at 03:07 UTC ( #936084=note: print w/replies, xml ) Need Help??

in reply to Re^3: Sorting issue
in thread Sorting issue

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.

Replies are listed 'Best First'.
Re^5: Sorting issue
by aaron_baugher (Curate) on Nov 05, 2011 at 13:47 UTC
    True, his sample data was already sorted that way; but it was only three lines, and he said he still needed to sort on that, so I assumed that was coincidence.
      The input file was already sorted by frequency. I tried without the sort command. It didn't give me the sorted results.

        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.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://936084]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (3)
As of 2018-04-21 02:24 GMT
Find Nodes?
    Voting Booth?