in reply to regex 1st match only
That code doesn't compile.
Assuming it did compile, one way to do what you're asking is this:
while( CONDITION_A ) { if( CONDITION_B ) { # DO SOMETHING last; # Exits loop immediately. } }
The last keyword is discussed in perlsyn and last. Some languages would call it break.
While I'm not among them, there are purists of structured programming who would advise against such short circuits as next, and last. They would prefer you jump through hoops such as this:
my $found = 0; while( CONDITION_A && ! $found ) { if( CONDITION_B ) { # DO_SOMETHING $found = 1; } else { # BLAH BLAH } }
In specific cases, such hoops may be able to be rendered less wordy. Either way, it's all just a matter of programming. ;)
Dave
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: regex 1st match only
by Laurent_R (Canon) on Oct 28, 2014 at 20:05 UTC | |
by BillKSmith (Monsignor) on Oct 28, 2014 at 21:49 UTC | |
by Laurent_R (Canon) on Oct 28, 2014 at 22:25 UTC |