As long as your input file is not too large you could slurp the whole file into one string and do global matches against it. Use the
s flag in the regex to allow the dot metacharacter to match newlines.
use strict;
use warnings;
open my $inputFH, q{<}, \ <<'END_OF_FILE' or die qq{open: $!\n};
end
sleep 10
dis qremote(MQSI.3PL846)RNAMERQMNAME1 : dis qremote(MQSI.3PL846) RNAME
+ RQMNAME
AMQ8409: Display Queue details.QUEUE(MQSI.3PL846)TYPE(QREMOTE)RQMNAME(
+MSTBKRQ1)RNAME(MQSI.3PL846)
end2 : end
Starting MQSC for queue manager NTTCSWQ1.
AMQ8409: Display Queue details.QUEUE(MQSI.3PL944)TYPE(QREMOTE)RQMNAME(
+MSTBKRQ1)RNAME(MQSI.3PL944)
exit
5724-H72 (C) Copyright IBM Corp. 1994, 2004. ALL RIGHTS RESERVED.
1 : dis qremote(MQSI.ADM850) RNAME RQMNAME
AMQ8409: Display Queue details.
QUEUE(MQSI.ADM850) TYPE(QREMOTE)
RQMNAME(MSTBKRQ1) RNAME(MQSI.ADM850)
2 : end
end
sleep 10
exit
AMQ8409: Display Queue details.
QUEUE(MQSI.ADMAPTR) TYPE(QREMOTE)
RQMNAME(MSTBKRQ1) RNAME(MQSI.ADMAPTR)
2 : end
One MQSC command read.
No commands have a syntax error.
All valid MQSC commands were processed.
END_OF_FILE
my $lines = do
{
local $/;
<$inputFH>;
};
close $inputFH or die qq{close: $!\n};
my $rxExtract = qr
{(?xs)
AMQ8409
.*?
QUEUE\(([^)]+)\)
.*?
RQMNAME\(([^)]+)\)
.*?
RNAME\(([^)]+)\)
};
while ( $lines =~ m{$rxExtract}g )
{
print qq{QUEUE: $1, RQMNAME: $2, RNAME: $3\n};
}
The output.
QUEUE: MQSI.3PL846, RQMNAME: MSTBKRQ1, RNAME: MQSI.3PL846
QUEUE: MQSI.3PL944, RQMNAME: MSTBKRQ1, RNAME: MQSI.3PL944
QUEUE: MQSI.ADM850, RQMNAME: MSTBKRQ1, RNAME: MQSI.ADM850
QUEUE: MQSI.ADMAPTR, RQMNAME: MSTBKRQ1, RNAME: MQSI.ADMAPTR
I hope this is helpful.
Cheers,
JohnGG
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.