in reply to regex help ...

perl -lne '$flag=1 if /loop/;$flag=0 if /endloop/; print if /warn/ && $flag' file.txt

Replies are listed 'Best First'.
Re: Re: regex help ...
by duff (Parson) on Nov 25, 2003 at 14:36 UTC

    Pardon me if I say ick! Every time I see "flag variables" I cringe. That could be written better (IMHO) like so: perl -ne 'next unless /loop/../endloop/; print if /warn/;' file.txt

      or just
      perl -ne 'print if /loop/../endloop/ and /warn/' file.txt

      The PerlMonk tr/// Advocate
      Nice.

      From perlop:

      Each ".." operator maintains its own boolean state. It is false as long as its left operand is false. Once the left operand is true, the range operator stays true until the right operand is true, AFTER which the range operator becomes false again.

      I had no idea about this before I saw your post. That will clean up many of my scripts quite a bit. Thanks for pointing that out.