in reply to more than one condition to a while loop
while (my $line = <INFILE>) { # Do a match against the line, grabbing the number. my ($num) = $line =~ /SEQRES\s{2,5}(\d)\s/; # This means that the line didn't meet our requirements # as defined by the regex. So, go get the next line. # (I added this ... you may not want it, depending on # what else you're doing in the loop.) next unless defined $num; # If that number is 2, leave the while loop. last if $num == 2; # Don't chomp unless there's a possibility we'll use it. chomp $line; # If the number is 1, print it to two places. if ($num == 1) { print "$line\n"; print OUTFILE "$line\n"; } }
Update: Changed code per tye's comments.
------
We are the carpenters and bricklayers of the Information Age.
The idea is a little like C++ templates, except not quite so brain-meltingly complicated. -- TheDamian, Exegesis 6
Please remember that I'm crufty and crochety. All opinions are purely mine and all code is untested, unless otherwise specified.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: more than one condition to a while loop (bug?)
by tye (Sage) on Aug 21, 2003 at 16:57 UTC | |
|
Re: Re: more than one condition to a while loop
by sauoq (Abbot) on Aug 21, 2003 at 21:21 UTC |