Off topic:Read 2 Files Perl
0
0
Entering edit mode
12.0 years ago

Perl newbie here: How can one input one file and compare it with two separate files(file 1 and file2) line by line for comparison in perl? After I input my main file then something like the code below may read two files but it isn't working for me..

open (MYFILE1, "test.txt");
@file1=<MYFILE>;
close MYFILE1;
open (MYFILE2, "test2.txt");
@file2=<MYFILE2>;
close MYFILE2;
foreach $line (@file1) {
  foreach (@file2) {
    if ($_ =~ /$line/) { 
        print $line;
    }
  }
}

is this okay?

read perl • 3.9k views
ADD COMMENT
This thread is not open. No new answers may be added
Traffic: 3277 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6