I have a unix program lets call it x that processes a file and takes the following parameters:
--fileName: just a text file name --firstLine: integer --lastLine: integer
so a typical invokation could be
x --fileName=foo --firstLine=50 --lastLine=100
this will read foo from line 5 to line 100 inclusive and produce do something with them

I want to call x few times with (--firstLine,--lastLine) like this

(1,1000) (1001,2000) ....

so effectively I am processing foo in chunks of 1000 lines

if I do this and foo has millions of lines the processing time will increase as I progress with the chunks because x is scanning foo to reach firstLine.

I cannot change x and want to write a Perl wrapper for x that reads foo from line 1 to the end and send every chunk of 1000 lines to x and this way I avoid scannig foo multiple times.

Is this possible?

update (broquaint): added formatting


In reply to splitting an input stream by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.