One way of approaching a problem of this kind is to find an effective way to represent the data. First, I'll assume your files are small enough to hold in memory. Putting files into an array of arrays:

my $ifs = '|'; # or whatever open FH, "<$file1path" or die $1; my @file1data = map {[split $ifs, $_]} <FH>; close(FH( or die $!; open FH, "<$file2path" or die $1; my @file2data = map {[split $ifs, $_]} <FH>; close(FH) or die $!;
Now we introduce a third array of arrays, for scores. It will have a row for each record in file1, and a column for each in file2. The number of matches will be stored in each:
my $lastrec = scalar( @{$file1data[0]}) - 1; my @scores = map { my $d1 = $_; # arrayref of a record from file11 [ map { # an arrayref with score for each record from + file2 my $d2 = $_; # arrayref of a record from file12 scalar grep { # count stringy matches $d1->[$_] eq $d2->[$_]; } 0..$lastrec; } @file2data ]; } @file1data;
At this point you can scan a row of @scores for the indexes of best match, or whatever statistics you want. This could have been done as well in nested for loops, but map is fun to play with. Warning, it compiles, but it's untested code.

After Compline,
Zaxo


In reply to (Mappy Approach) Re: Comparing fields in 1 database with fields in another by Zaxo
in thread 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.