This is a test version of Biostars. For the public version, visit https://www.biostars.org.
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?

read perl

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.

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.

0 answers

No answers yet.

Log in to answer this question.