Trying to process the two files in parallel is a bad idea. Assuming that text2 is not huge, read it first and create a hash entry for each file entry.

Then read text1 and use the hash to check to see if there is a matching entry in text2:

use strict; use warnings; my $text1 = <<'END_TEXT'; 2343/45/45/cal/ca-1.xml 2343/45/45/ca-1 6534/534/34/car/ca-5.xml 6534/534/34/ca-5 END_TEXT my $text2 = <<'END_TEXT'; 6534/534/34/ca-5 5676/435/734/da-1 END_TEXT my %text2Entries; # Build a hash table of text2 entries open my $inFile, '<', \$text2 or die "Unable to read text2: $!\n"; while (<$inFile>) { chomp; ++$text2Entries{lc $_}; } close $inFile; # Read the text1 entries and print any that don't have a text2 entry open $inFile, '<', \$text1 or die "Unable to read text1: $!\n"; while (my $line = <$inFile>) { my ($part1, $part2) = split /\s+/, $line; chomp $part2; next if ! exists $text2Entries{lc $part2}; print $line; } close $inFile;

Prints:

6534/534/34/car/ca-5.xml 6534/534/34/ca-5

Don't get hung up on the two $text strings - that's just so I can provide a runnable test script without requiring external files.


True laziness is hard work

In reply to Re: Read two files and print by GrandFather
in thread Read two files and print by sandy1028

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.