in reply to Re^2: How to find content between KEYWORD and BLANKLINE then print it
in thread How to find content between KEYWORD and BLANKLINE then print it

Thanks for the correction. I was hewing as closely as possible to the OP's code and didn't test before posting; I guess I've always used it with $_. Updated and noted in my reply.


The way forward always starts with a minimal test.
  • Comment on Re^3: How to find content between KEYWORD and BLANKLINE then print it
  • Download Code

Replies are listed 'Best First'.
Re^4: How to find content between KEYWORD and BLANKLINE then print it
by johngg (Canon) on Jan 07, 2016 at 11:22 UTC

    You can still use a lexical but you have to be explicit about what is being matched, also taking care with the difference in precedence of and and &&. With lower precedence and:-

    $ perl -Mstrict -Mwarnings -E ' open my $inFH, q{<}, \ <<EOD or die $!; Seb Xavier Peter Roland Jim Xerox Paddle Yoyo EOD while ( my $line = <$inFH> ) { print $line if $line =~ m{X} .. $line =~ m{^\s*$} and $line !~ m{^\s*$}; }' Xavier Peter Xerox Paddle $

    Higher precedence && requires parentheses:-

    $ perl -Mstrict -Mwarnings -E ' open my $inFH, q{<}, \ <<EOD or die $!; Seb Xavier Peter Roland Jim Xerox Paddle Yoyo EOD while ( my $line = <$inFH> ) { print $line if ( $line =~ m{X} .. $line =~ m{^\s*$} ) && $line !~ m{^\s*$}; }' Xavier Peter Xerox Paddle $

    Cheers,

    JohnGG