in reply to Re: A way to avoid repeated conditional loops
in thread A way to avoid repeated conditional loops

If 'some code #2' is very small or can be packaged into a single function call, I might go with that. Or I might just make it obvious that we only want/expect this once in the one loop:
my $got_alpha; while (<FILE>) { unless ($got_alpha) { if (/alpha/) { #...alpha code $got_alpha++; next; } } # ...more code }
Update: And I just noticed the part in the OP where it says "without a flag variable"...oh, well...

Replies are listed 'Best First'.
Re^3: A way to avoid repeated conditional loops
by AR (Friar) on Aug 24, 2011 at 17:04 UTC

    I think you missed the point of the original post. Deus Ex wants to get rid of running the conditional as soon as "alpha" is seen. Your code substitutes that for another conditional (that doesn't use the regex engine, but still).