On Fri, 2006-31-03 at 15:45 -0800, Tom Phoenix wrote: > You should loop over the input, pushing each item on to an array. If > at any time you have 2000 items in the array, sort them and discard > any you don't want to keep. > > $#data = 999 if $#data > 999; # OBperl: one way to discard elements > > When you finish looping, sort-and-discard again. You'll never need > more than 2N items in memory at any given time. Does that algorithm > work for your needs?
Sorting is not necessary. If he keeps an array of the best, that means lowest, records then all he has to do is compare every new entry with the highest. This is called "fail early." This means, if it's going to fail, it should at the earliest opportunity. If it succeeds then it searches down thru the list, to find its place. This is called "succeed early." Given that the procedure can flip between these two methods, it is faster than any sort. -- __END__ Just my 0.00000002 million dollars worth, --- Shawn "For the things we have to learn before we can do them, we learn by doing them." Aristotle * Perl tutorials at http://perlmonks.org/?node=Tutorials * A searchable perldoc is at http://perldoc.perl.org/ -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>