I did do a print $x if "Patient" is matchedAre you sure you are actually entering this section, i.e. did you do a distinctive print STDERR from that section (not just a match on patient or vague print "matched here")? As in:and
When I put this print in the match condition I want to break the loop, the print comes along at the right place, it's just that the loop continues. if ( $x =~ m/^Patient/ ) { print "matched here "; #goto WID; last WID; }
... if ($x =~ m/^Patient/) { print STDERR "Patient found\n"; #added for verification last WID; } ...
If you have a match on the ENCODE stuff at the top of the loop, your $x will be set to "Patient" (with quotes) and will match m/^"Patient/ and /Patient/ but not m/^Patient/.
Failing that, I would try to comment out everything except the stuff at the top that sets $x and the if ... last WID stuff and see if you still have the wierd behavior. If you do, start simplifying the code that sets $x until you don't. Then start adding stuff back until you do. The key thing is to isolate the code that triggers this odd behavior.
Best, beth
Update: added quotes of previous debugging efforts, plus some extra suggestions.
In reply to Re: Break perl foreach loop
by ELISHEVA
in thread Break perl foreach loop
by pvecchio
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |