Hello,

I have two flatfile databases (let's call them file1 and file2), each with a number of lines. Say, file1 has 2 lines, and file 2 has 4 lines. Each line in each database has exactly the same delimited fields. I need to keep the 2 files separate, though.

I want to take the first line in file1, and then compare it with each of the 4 lines in file2, to see which fields are the same. So out of 10 possible fields, line 1 in file1 might have 6 matches with line 1 file2, 3 matches with line 2 file2, 7 matches with line 3 file2, and 1 match with line4 file2. I then need to be able to list the number of matches for each line of file 2 with line 1 file 1, and state what the matches are.

Once that's done, I want to repeat the above paragraph for the second line in file1. So, I need to treat each line in file 1 separately, but I need to compare it with every line in file 2.

The output might be:

Line 1 of File 1 has 6 matches with file2line1. These are... Line 1 of File 1 has 3 matches with file2line2. These are... etc etc etc Line 2 of File 1 has 8 matches with file2line1. These are... etc etc etc

Is this possible? Is it easy? I have been trying to do it using foreach loops, but my brain can't handle the logic at this stage.

Any ideas?

Thanks

edit - Petruchio Tue Oct 16 11:37:04 UTC 2001: Added markup.


In reply to Comparing fields in 1 database with fields in another by rline

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.