Hello all, I am a newbie and this is my first post so thanks in advance for any help. I am having trouble with what should be an easy part of a larger script. The result of the code below is a file with more lines than elements in the array (@isos20) used in the grep. I have done this multiple ways and can't figure out why grep is matching more than one line for some elements (if that's really the problem). The lines of the file to read are formatted like this:
comp1234_c0_seq1,1,5,3,8,0,6,...
where the string before the first comma is an ID in which numbers vary but the letters are consistent throughout and that potentially exists in @isos20.
Here is the code I have now:
#open file to write filtered lines to open (OUT2, ">$pos_two") or die "cannot open $pos_two "; #open file to filter open (IN2, "<$posfile") or die "cannot open $posfile "; while (<IN2>) { chomp(my $line = $_); if ($line =~ m/(comp\d+_c\d+_seq\d+),.+/) { my $comp = $1; if (grep (/$comp/, @isos20)) { print OUT2 "$line\n"; } } } close IN2; close OUT2;
I can only guess that the grep is matching more than one line for some of the elements in @isos20 but I don't know why that would happen - unless the $comp variable is actually a regex and not a literal string. Thanks very much for any help. I know this must be a simple fix but I am at a loss.
Best,
BD
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |