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.
In reply to Re: Read two files and print
by GrandFather
in thread Read two files and print
by sandy1028
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |