Hi, welcome. It's a FAQ, there are tons of threads about it in this monastery. Have you searched? Do you know what your code does, or did you copy it from somewhere without really understanding it? As a beginner, have you worked through perlintro yet? You'll also need perlrequick if you are doing text matching.
You must always use strict; and use warnings; at the top of your code.
For example, warnings would have told you that you were trying to read from a closed filehandle.
(If you close the comparison filehandle first time through the loop the rest of the lines in the id file never have a chance to match.)
Don't copy this. (edit: because it won't work, as Laurent_R points out below. I was trying to show some errors in your code, (see above), but as others have noted your overall approach is wrong to begin with for your task.) Try to spot the differences. Ask if you have any questions:
(untested)
#!/usr/bin/perl
use strict; use warnings;
my $file_id = './BreastCnAPmiRNAsID.txt';
open( my $FILEID, '<', $file_id ) or die "Died: cannot open $file_id: $!";
my $file_comp = './tarbaseData.txt';
open( my $FILECOMPARE, '<', $file_comp ) or die "Died: cannot open $file_comp: $!";
while ( my $id = <FILEID> ) {
chomp $id;
while ( my $comp = <FILECOMPARE> ) {
chomp $comp;
print "$id\n";
if ( $comp =~ /$id/ ) {
print "\t$_\n";
} else {
print "\tno match\n";
}
}
}
close $FILEID;
close $FILECOMPARE;
__END__
Hope this helps!
In reply to Re: comparing an ID fom one file to the records in the second file
by 1nickt
in thread comparing an ID fom one file to the records in the second file
by ag88
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |