good chemistry is complicated, and a little bit messy -LW |
|
PerlMonks |
in reply to Re^2: Matching a string in a parenthesized block (regex help)
in thread Matching a string in a parenthesized block (regex help)
Here an implementation
Please note how ...
use strict; use warnings; my $section; my $hit; while (<DATA>) { my $start = /^ASDF \{\s*$/; #(2) my $end = /^\}\s*$/; if ($start .. $end) { $section .= $_; $hit = 1 if /foo_match/; } if ($end and $hit) { print $section; $section = $hit = ""; # reset (1) } } __DATA__ ASDF { tmp foo_match tmp } string2 { tmp } ASDF { tmp bar_match tmp }
NB:
Cheers Rolf
(addicted to the Perl Programming Language :)
Wikisyntax for the Monastery
|
---|