Read 2 Files Perl
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?
• 4,055 views
•
link
0 answers
No answers yet.
Log in to answer this question.
You should format your code so that it is readable. Also, what is not working? Are you getting errors, or do you not get the expected output (what is your expected output)? Lastly, it is probably better to ask this question at http://stackoverflow.com/, because it is only programming related.
Thanks Niek. I will ask my question there.
This is a straight perl question, which is probably off-topic on a bioinformatics forum. Also, diff (if you're using Linux) or something like DiffMerge(If you're using Windows) might do what you want. You might want to provide more context to show how your question is relevant to bioinformatics, and why you want to do this.