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

That looks great, but that only prints out the first name{} entry and not hte second, so it looks like it trys to create each name{} as a single string. Maybe that is the way to go is there a quick way to read the file and put it into a sinlge string ? for each name{] entry

Replies are listed 'Best First'.
Re^3: Grouping strings over a few line
by bart (Canon) on Oct 13, 2006 at 20:11 UTC
    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; }