in reply to Doing "it" only once

There's also a shortcut: the flip-flop operator:

while (<>) { if (1 eq (/foo/ .. (1x0))) { do_something(); } }
this will not check for /foo/ once it's found.

Of course, this is not any better than

my $found; while (<>) { if (!$found && /foo/) { $found++; do_something() } }

Replies are listed 'Best First'.
Re^2: Doing "it" only once
by Roy Johnson (Monsignor) on Sep 21, 2005 at 19:28 UTC
    The shorter cut is the match only once operator that is built-in to Perl.

    Caution: Contents may have been coded under pressure.

      Sure, but that works only for a regexp, not for any condition.