![]() |
|
Syntactic Confectionery Delight | |
PerlMonks |
Re: splitting an input streamby BrowserUk (Patriarch) |
on Nov 07, 2003 at 12:21 UTC ( #305280=note: print w/replies, xml ) | Need Help?? |
Update: Corion ++ pointed out that I reversed the sense of your problem, sorry for my confusion. Instead, have your wrapper script read 1000 lines from foo, put them in a temporary file and then invoke X. Repeat till done.
Instead of having X supply you 1000 lines at a time, ask for them all and pipe the result to your perl script. In your perl script, read 1000 lines from the pipe into an array, process them, then loop back and get the next 1000 lines. Repeat till done. The output of X will be blocked while your script processes each batch of 1000 lines. Your script will only ever have to hold 1000 lines in memory at a time. X will never have to backtrack or skip over any lines. A silly example. (One liner wrapped for display)
The first instance of perl just reads the file junk (one integer per line), and prints it to stdout. The second instance, loops, reading 10 lines, chomping them, reversing them and printing them before emptying the array and going back for the next 10. Examine what is said, not who speaks.
"Efficiency is intelligent laziness." -David Dunham"Think for yourself!" - Abigail Hooray! Wanted!
In Section
Seekers of Perl Wisdom
|
|