in reply to Re: Re: Help Matching Sections of a file
in thread Help Matching Sections of a file

How about (not well tested):
while (<FOO>) { print if /Port\s+$port\b/ .. /^#---/ && last; }
The last also fixes the (presumed) problem of looping through the whole file even after you've found the relevant section. Notice the \b too which I forgot.

Replies are listed 'Best First'.
Re: Re: Re: Re: Help Matching Sections of a file
by Elijah (Hermit) on Apr 05, 2004 at 15:17 UTC
    What if you have multiple iterations of the same target search and you want to print them all to stdout? Your solution would fail in this arena.

      Aye, it would. I can't find a prettier solution than:

      while (<FOO>) { if (my $ln = /bar/ .. /baz/) { print unless $ln =~ /E/; } }