in reply to Re^2: Grouping strings over a few line
in thread Grouping strings over a few line

OK I experimented a little with eof, and I found eof (no handle, no parens) returns true on the last line. So If I extend the end side of the flipflop operator with an extra test on eof, and set a flag to true only if it succeeds because of this extra test, then I can safely check for the last match, too. I do need to modify the regex a little to allow for this, too.
#! perl -w my $buffer; LINE: while(<DATA>) { my $eof; # flase by default if(my $counter = (/^name\s.*\{/ ... (/^name\s.*\{/ || ($eof = eof) +))) { if($counter == 1) { # begin $buffer = ''; } $buffer .= $_; if($counter =~ /E/) { # end if($buffer =~ /name(.*?)(^name|\z)/ms) { print "Found: $1\n"; } redo LINE unless $eof; # retry with same line, unless en +d condition is BECAUSE OF eof } } } __DATA__ name value { test 1; test 2; test 5; } name three { eat 4; eat 5; } name four { eat 6; eat 7; }
Result:
Found: value { test 1; test 2; test 5; } Found: three { eat 4; eat 5; } Found: four { eat 6; eat 7; }