in reply to Re: How to find content between KEYWORD and BLANKLINE then print it
in thread How to find content between KEYWORD and BLANKLINE then print it
I'll ++ your post as soon as I get votes. It still contains a mistake though. Since =~ is of higher precedence than .., your code is actually parsed as ($line =~ /X/i) .. /^\s*$/ which means the second regex will be applied on $_. Adding parentheses like this: $str =~ (/A/../B/) won't work either because this will apply the regular expressions first, on $_ (and this also happens to be the range operator, not flip flop).
Here, using the default variable $_ is the best option for readability:
while (<DATA>) { if (/A/../B/) { print; } } __DATA__ 1 2 A 3 4 B 5 6
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: How to find content between KEYWORD and BLANKLINE then print it
by johngg (Canon) on Jan 06, 2016 at 23:51 UTC | |
by choroba (Cardinal) on Jan 07, 2016 at 13:39 UTC | |
|
Re^3: How to find content between KEYWORD and BLANKLINE then print it
by ChrisCK (Initiate) on Jan 06, 2016 at 23:44 UTC | |
|
Re^3: How to find content between KEYWORD and BLANKLINE then print it
by 1nickt (Canon) on Jan 07, 2016 at 01:48 UTC | |
by johngg (Canon) on Jan 07, 2016 at 11:22 UTC |