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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |