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


In reply to Re: capturing from Input file by johngg
in thread capturing from Input file by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.