in reply to Break perl foreach loop
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.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Break perl foreach loop
by pvecchio (Initiate) on Mar 03, 2009 at 19:33 UTC | |
by ELISHEVA (Prior) on Mar 03, 2009 at 19:50 UTC | |
by Marshall (Canon) on Mar 03, 2009 at 19:56 UTC | |
by chromatic (Archbishop) on Mar 03, 2009 at 20:09 UTC | |
by Marshall (Canon) on Mar 04, 2009 at 17:08 UTC |