in reply to more than one condition to a while loop
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
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: more than one condition to a while loop
by davido (Cardinal) on Aug 21, 2003 at 17:01 UTC | |
|
Re: Re: more than one condition to a while loop
by anchorite (Initiate) on Aug 21, 2003 at 16:58 UTC |