This might be trivial and possibly a dumb question but I'm seeking the wisdom of my fellow perl monks. Consider the following script:
#!/usr/bin/perl -w # use strict; while (<DATA>) { print if my $que_def = /^QueueManager:\s*$/ ... /^QueueManager:\s*$/; # print if my $que_def = /^QueueManager:\s*$/ .. /^QueueManager:\s*$/; } exit 0; __END__ ClientExitPath: ExitsDefaultPath=/var/mqm/exits LogDefaults: LogPrimaryFiles=3 LogSecondaryFiles=2 LogFilePages=1024 LogType=CIRCULAR LogBufferPages=0 LogDefaultPath=/var/mqm/log QueueManager: Name=venus.queue.manager Prefix=/MQHA/venus.queue.manager/data Directory=venus!queue!manager QueueManager: Name=craig.queue.manager Prefix=/MQHA/craig.queue.manager/data Directory=craig!queue!manager QueueManager: Name=ha.qmgr1 Prefix=/MQHA/ha.qmgr1/data Directory=ha!qmgr1 QueueManager: Name=test.manager Prefix=/MQHA/test.manager/data Directory=test!manager
What I'm trying to do is to parse the <key> = <value> fields following each "QueueManager:" line. I am trying to understand and use the '..' and/or the '...' range operators to extract only the lines between the "QueueManager:" tags. I inserted an "EndQueueManager:" line before each "QueueManager:" line in the configuration file and my script worked fine but I don't have control of the format of the config file. (It's created by IBM's WebSphere/MQ Series software). I have managed to accomplish my objevtive in a more brute force method but now I'm trying to educate myself here and learn a more elegant solution. I need to start processing a given queue manager stanza on the first "QueueManager:" line and end it on the line immediately preceeding the next "QueueManager:" line. I also want to handle an aribitrary number of <key> = <value> pairs. If I use the '..' operator I get only the "QueueManager:" lines and not the data between them. If I use the '...' operator then I get every odd stanza and skip over the even stanzas. HELP!

In reply to parsing a config file by Gorio3721

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.