The data you are processing looks like c program. You are right to use s modifier to take data as a single line.
I quickly come up with something, and hope it helps: (Well, I do not handle things like brackets in quotes, (unmatched) brackets in comments, but in your real code, you have to expect those)
use strict; use warnings; open(CPROG, "<test1.cpp"); my $concat_line; while (my $line = <CPROG>) { if ($line =~ /\(/s) { $concat_line = $line; } else { $concat_line .= $line if ($concat_line); } if ($concat_line && ($concat_line =~ /\(.*\)/s)) { print $concat_line; $concat_line = undef; } } close(CPROG);
I tried it with
#include <string.h> #include <stdio.h> main() { char a[80]; strcpy(a, "abcd"); strcat(a, "\015"); printf("%s", a); }
And it gives me:
main() { strcpy(a, "abcd"); strcat(a, "\015"); printf("%s", a);
In reply to Re: Trouble matching more than one line
by pg
in thread Trouble matching more than one line
by Levan
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |