I am simply checking through a file of records, looking for any that match and then extracting that particular record.
My problem is that if I find one that matches, my code takes all the records from then onwards, regardless of whether they pass the criteria.
The file of records looks something like this:
I am simply trying to check the numbers (e.g 99-143) against an array of numbers and pull out that particular record if it matches. Please have a look at my code to see where i'm going wrong: Many thanks>RC|ae000001||99-143 ACGFEHIGJUHIDFHDIHGFHHIIFHIHHFBIHB DHFIJHGIJFIGKFKPDOKFKFKFFFFF >RC|ae000002|150-179 THDFHOIHDIOVIJJOFPJGFJVOKVKFFKBDJK HHTHTHTHAAAAA >RC|ae000003|185-207 KLJDJFGJFJDJFKJKJFSJFKDHSHKFJKDJDK SAJSAJJSDSPIDOSDKSKFKF
foreach my $l (@file) { if (($l =~ /^>(\w{2})(.{1})(\w{2}\d{6}.{2})(\D?)(\d+)(\W{1})(\d+)/ +)) { $current = undef; if ($4) { $hit = "$7-$5"; } else { $hit = "$5-$7"; } } foreach my $k (@positions) { if ($k == $hit) { $in_gene = 1; } } if ($in_gene) { $gene .= $l; } unless ($l =~ /^>/) { next; } } print $gene;
In reply to using flags by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |