I have two files that are several hundred MB in size. These files each contain a sorted key. What I would like to do is read each line from each file one at a time. If a match is found, write it out to a “matched” file otherwise write to one of two “nonmatch” files. The main issue that I need to avoid is reading the files into memory. I think I understand how I want to test the condition, what I don't understand is how the looping will work.
input files file0 file1 1 2 2 4 3 5 5 8 7 9 9 logical test 1<=>2 -1 next 0, keep 1, print to nomatch0 2<=>2 0 next 0, next 1, print to match 3<=>4 -1 next 0, keep 1, print to nomatch0 5<=>4 1 keep 0, next 1, print to nomatch1 5<=>5 0 next 0, next 1, print to match 7<=>8 -1 next 0, keep 1, print to nomatch0 9<=>8 1 keep 0, next 1, print to nomatch1 9<=>9 0 next 0, next 1, print to match output files matched nomatch0 nomatch1 2 1 4 5 3 8 9 7

In reply to need help reading through two large files and output matches and non matches by jlctx

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.