in reply to Match within array
my $i = (0 .. 13005);
That's where your problems start; the code is not doing what you expect. Using 0 .. 13005 in scalar context is not a range, but a flip flop, so $i now contains 1. Surprise, surprise.
if ($probe_ID =~ m/$probe_name[$i]/) #match the current entry with the list of probe names
Consequently this doesn't do what you want it to - it just checks against $probe_name[1], not all the probe names.
One approach is to build a regex instead:
# afater the first loop: my $probes_regex = join '|', @probe_name; # you don't need to store all lines in @line, it only wastes memory while (my $line = <DATA>) { my @data = split /\t/, $line; if ($data[0] =~ $probes_regex) { print OUT "$gene[$i]\t$line\n"; } else { print "no match\n"; } }
But if you don't want or need regex matches, but rather exact matches, a hash is much more efficient.
In general it pays off if you tell us about how your data looks like, there might be ways to speed up or simplify the process quite a bit.
|
|---|