Question: (Closed) Read 2 Files Perl
gravatar for bioinformatics123
8.1 years ago by
bioinformatics12310 wrote:

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");
close MYFILE1;
open (MYFILE2, "test2.txt");
close MYFILE2;
foreach $line (@file1) {
  foreach (@file2) {
    if ($_ =~ /$line/) { 
        print $line;

is this okay?

perl read • 3.0k views
ADD COMMENTlink modified 8.1 years ago by Istvan Albert ♦♦ 84k • written 8.1 years ago by bioinformatics12310

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, because it is only programming related.

ADD REPLYlink modified 8.1 years ago • written 8.1 years ago by Niek De Klein2.5k

Thanks Niek. I will ask my question there.

ADD REPLYlink written 8.1 years ago by bioinformatics12310

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.

ADD REPLYlink written 8.1 years ago by Eric Fournier1.4k
Please log in to add an answer.
The thread is closed. No new answers may be added.


Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.3.0
Traffic: 920 users visited in the last hour