It's generally good form to indicate if you've Crossposted to Stack Overflow and Unix & Linux Stack Exchange to prevent duplication of effort.

The answer I posted on Stack Overflow was:

#!/usr/bin/env perl use strict; use warnings; use Data::Dumper; #read file1 into a hash - but invert is it's value => key instead: # 'CKEIFJ' => 'cmr03lsp', # etc. open( my $file1, '<', "file1.txt" ) or die $!; my %file1_content = map { reverse split } <$file1>; close($file1); print Dumper \%file1_content; #read file 2 - read keys, store the values. #split _2_ fields, so we keep both numbers as a substring: #e.g.: # 'cmr03lsp' => '60 70 #', open( my $file2, '<', "file2.txt" ) or die $!; my %file2_content = map { split( " ", $_, 2 ) } <$file2>; close($file2); print Dumper \%file2_content; #then iterate file 3, checking if: #file1 has a matching 'key' (but inverted - as a value) #file2 has a cross reference. open( my $file3, '<', "file3.txt" ) or die $!; while ( my $line = <$file3> ) { chomp $line; if ( $file1_content{$line} and $file2_content{ $file1_content{$line} } ) { print "$file1_content{$line} $line $file2_content{$file1_con +tent{$line}}"; } } close($file3);

Which prints (aside from Dumper diag content):

fji01dde AIDJFMGKG 25 30 cmr03lsp CKEIFJ 60 70

as requested


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