Hi,

this is a simplified version checking 3 files:

use strict; use warnings; my %result; open my $A, "<", "file1" or die "could not open file1 $!"; while (<$A>) { chomp; my $key = (split /\t/, $_)[0]; $result{$key} = 1; } close $A; open my $B, "<", "file2" or die "could not open file2 $!"; while (<$B>) { chomp; my $key = (split /\t/, $_)[0]; $result{$key}++; } close $B; open my $C, "<", "file3" or die "could not open file3 $!"; while (<$C>) { chomp; my $key = (split /\t/, $_)[0]; if ($result{$key} == 2) { # this key has been seen in both previou +s files print "Line with $key is present in all three files\n"; } } close $C;
The value in the %result hash is basically a counter saying how many times you've seen the key. If you find in file3 a key that has already been seen twice, then the key is present in all 3 files. Please note that this assumes that the key cannot be more than once in file2, but only rather small changes would be required to take this possibility into account.

Update: when reading your answer, I only reread the narrative of your original post, without looking at the file samples. I assumed above that all your three files had the same structure, but only see now that they don't. A few minor changes are needed to cope with the actual structure of your files, but I guess that I still gave you the general idea of the solution.


In reply to Re^3: Compare 3 files and print matches in Perl by Laurent_R
in thread Compare 3 files and print matches in Perl 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.