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

Re^4: Sorting issue

by Cristoforo (Deacon)
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.


Comment on Re^4: Sorting issue
Re^5: Sorting issue
by aaron_baugher (Deacon) 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?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://936084]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (8)
As of 2014-12-25 08:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (159 votes), past polls