foreach my $line1(@array1) { foreach my $line2(@array2) if { $line1=~ /^$pattern/; $line2=~ /^$pattern/; $line1==$line2; { print $line1; } }
Your code has syntax error.
moreover eq is for comparing strings. == is for comparing numbers. Adding code:#!/usr/bin/perl use strict; use warnings; open(FH, "<","./file1.txt") or die "Can't Open File1\n"; open(BH, "<","./file2.txt") or die "Can't Open File2\n"; my $pattern='^LOC_Os0[1-7]g[0-9]*.[0-9]\s'; while(my $line1 = <FH>) { chomp($line1); #print "Line1:$line1\n"; if( $line1=~ /$pattern/) { while(my $line2 = <BH>) { chomp($line2); if($line2 =~ /$pattern/) { if($line1 eq $line2) { print "Matches: ". $line1; } else { print "nothing to print\n"; } } } seek(BH,0,0); } } close(FH); close(BH);
file1.txt
LOC_Os01g01010.1 3017 : PAS 2993,3017 : AGTAAA AAATGGAGGAATTCTGCCA LOC_Os01g01010.2 2218 : uORF 7,129 : ATG AAGAAGACGAGACGACGACTTCCCCACTA +GGAAACACGACGGAGGCGGAGATGATC
file2.txt
LOC_Os01g01010.1 : PS51373 HIPIP High potential iron-sulfur proteins f +amily profile. 2139 - 2208 AATGATTTATCATGTGAGGTGAAAGA-----AGAGCACCGGG +TGAACAGTTACACAAGAA L=-1 GAAAGTCCAAAAGCA LOC_Os01g01010.2 : PS00022 EGF_1 EGF-like domain signature 1. 298 - 30 +9 CtCccTtcGTtC L=(-1 LOC_Os01g01010.2 2218 : uORF 7,129 : ATG AAGAAGACGAGACGACGACTTCCCCACTA +GGAAACACGACGGAGGCGGAGATGATC
In reply to Re: match pattern from two different file
by vinoth.ree
in thread match pattern from two different file
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |