Why do you keep reopening the second file? That's probably not doing what you want. (Update: yes, that is what you want. Silly me. I should have put in the seek that vennirajan listed.)

Try the following debugging code:

print "'$probes[1]'";

Also, let's clean this up a bit (making the possibly false assumption that you want a tighter scope for the arrays since you overwrite them).

my ($file1, $file2) = qw(file1 file2); open INDAT, "<", $file1 or die "Cannot open ($file1) for reading: $!" +; open INCOMP, "<", $file2 or die "Cannot open ($file2) for reading: $!" +; while (defined (my $line = <INDAT>)) { chomp $line; # remove newline my @array = split /\t/, $line; while (defined (my $line = <INCOMP>)) { chomp $line; my @probes = split /\t/, $line; # using \Q and \E to avoid having regex meta character problem +s # see "perldoc perlre" if ($array[0] =~ /\Q$probes[1]\E/i) { print "Found $probes[1]\n"; } } } close INCOMP; close INDAT;

That should get you closer to what you're looking for. Note that we only open each file once. We also remove the newline from each line to ensure that you're not accidentally trying to match that. Also, read perlre to see how \Q and \E work (the \E is actually not necessary in the above example).

If you're using an older Perl, my three-argument open syntax won't work and you'll have to do this:

open FH, "<$file1" ... # or open FH, $file1 ...

Cheers,
Ovid

New address of my CGI Course.


In reply to Re: beginner regex question by Ovid
in thread beginner regex question by natoikos

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



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.