capturing multiple statement, which starts with "msg_pri"

G

guru

Hi All,

I have one requirement where I need to capture statement beginning
with "msg_pri". This may span multiple lines.

Cases
1. msg_pri (........................);
2. msg_pri (........................)
3. msg_pri (........................) \

other cases
same as above , but they may span multiple lines.

4. msg_pri (........................,
..............);

Below perl script convert multiple line msg_pri in to single line and
handling case 1 and case 2, 4.

It is not handling the case 3. It will hang when it encounters case 3.

system("perl -i -ne \' unless(<EOF>){ if(/msg_pri.?\\(/i) { until(/[\;
\)]\$/) { chomp; s/\\s+/ /; print; \$_ = <>;} s/\\s+/ /;} print }\'
$process_file");

I modified "until(/[\;\)]\$/" to "until(/[\\\;\)]\$" in the above
statement then also it is not handling.

How to modify this to handle all the above cases or any other way to
do this in perl.

Please let me know if you need any other info.

Thanks & Regards
Gururaja
 
J

John W. Krahn

guru said:
I have one requirement where I need to capture statement beginning
with "msg_pri". This may span multiple lines.

Cases
1. msg_pri (........................);
2. msg_pri (........................)
3. msg_pri (........................) \

other cases
same as above , but they may span multiple lines.

4. msg_pri (........................,
..............);

Below perl script convert multiple line msg_pri in to single line and
handling case 1 and case 2, 4.

It is not handling the case 3. It will hang when it encounters case 3.

system("perl -i -ne \' unless(<EOF>){ if(/msg_pri.?\\(/i) { until(/[\;

Why system? Are you running this in perl as a separate process, and if
so why? Where did the EOF filehandle come from? It is not doing
anything in your example.

\)]\$/) { chomp; s/\\s+/ /; print; \$_ = <>;} s/\\s+/ /;} print }\'
$process_file");

Converting that to usable Perl code:

local ( $^I, @ARGV ) = ( '', $process_file );
while ( <> ) {
unless ( <EOF> ) {
if ( /msg_pri.?\(/i ) {
until ( /[;)]$/ ) {
chomp;
s/\s+/ /;
print;
$_ = <>;
}
s/\s+/ /;
}
print
}
}

I modified "until(/[\;\)]\$/" to "until(/[\\\;\)]\$" in the above
statement then also it is not handling.

How to modify this to handle all the above cases or any other way to
do this in perl.

Please let me know if you need any other info.

What determines "a single line"? What do you want the output to look like?



John
 
G

guru

guru said:
I have one requirement where I need to capture statement beginning
with "msg_pri". This may span multiple lines.
Cases
1. msg_pri (........................);
2. msg_pri (........................)
3. msg_pri (........................) \
other cases
same as above , but they may span multiple lines.
4. msg_pri (........................,
                       ..............);
Below perl script convert multiple line msg_pri in to single line and
handling case 1 and case 2, 4.
It is not handling the case 3. It will hang when it encounters case 3.
system("perl -i -ne  \' unless(<EOF>){ if(/msg_pri.?\\(/i) { until(/[\;

Why system?  Are you running this in perl as a separate process, and if
so why?  Where did the EOF filehandle come from?  It is not doing
anything in your example.
\)]\$/) { chomp; s/\\s+/ /; print; \$_ = <>;} s/\\s+/ /;} print }\'
$process_file");

Converting that to usable Perl code:

local ( $^I, @ARGV ) = ( '', $process_file );
while ( <> ) {
     unless ( <EOF> ) {
         if ( /msg_pri.?\(/i ) {
             until ( /[;)]$/ ) {
                 chomp;
                 s/\s+/ /;
                 print;
                 $_ = <>;
                 }
             s/\s+/ /;
             }
         print
         }
     }
I modified "until(/[\;\)]\$/" to "until(/[\\\;\)]\$" in the above
statement then also it is not handling.
How to modify this to handle all the above cases or any other way to
do this in perl.
Please let me know if you need any other info.

What determines "a single line"?  What do you want the output to look like?

John
--
Those people who think they know everything are a great
annoyance to those of us who do.        -- Isaac Asimov- Hide quoted text -

- Show quoted text -

until(/[\;\)]\$/)

in the unitl , pattern matching [\;\)]\$ will determined whether line
ending with ; or ). if it ends and spans multiple line then it will
convert it to single line.

msg_pri (........................,
..............);

to

msg_prin (............................);

this pattern matching fails if it line ends with \

3. msg_pri (........................, \
....................) \

Regards
Gururaja
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,213
Messages
2,571,108
Members
47,699
Latest member
lovelybaghel

Latest Threads

Top