Try this:

while ( <INFILE> ) { chomp; if ( /^SEQRES[\s]{2,5}1\s/ ) { print "$_\n"; print OUTFILE "$_\n"; } elsif ( /^SEQRES[\s]{2,5}2\s/ ) { last; } }

The above snippet should print everything that matches the first rexexp, and continue iterating through the loop, printing lines that match the first regexp, until a line matches the second regexp, at which time the loop exits. If the second regexp never matches, the loop exits when there's no more file to read.

Note the use of last; last basically jumps to the end of the current block or loop, as though the loop's criteria suddenly became false. continue wouldn't work, because continue just skips up until the end of the current iteration and then lets the loop continue iterating. And break doesn't work because, as you find in the index of the Camel book, "Break: See last".

Though this isn't what your code was doing, it is nevertheless, what your description of the problem said you intended to do.

Hope this helps!

Dave

"If I had my life to do over again, I'd be a plumber." -- Albert Einstein


In reply to Re: more than one condition to a while loop by davido
in thread more than one condition to a while loop by anchorite

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.