Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

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

All is well

In reply to Re: match pattern from two different file by vinoth.ree
in thread match pattern from two different file by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (5)
As of 2024-04-25 11:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found