Hi monks, I wondered if I could have some help using flags.

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:

>RC|ae000001||99-143 ACGFEHIGJUHIDFHDIHGFHHIIFHIHHFBIHB DHFIJHGIJFIGKFKPDOKFKFKFFFFF >RC|ae000002|150-179 THDFHOIHDIOVIJJOFPJGFJVOKVKFFKBDJK HHTHTHTHAAAAA >RC|ae000003|185-207 KLJDJFGJFJDJFKJKJFSJFKDHSHKFJKDJDK SAJSAJJSDSPIDOSDKSKFKF
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
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

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.