The following is untested; it's also not uber-leet, but then what do I care about that? =)
# place to put everything
my @queue_managers;
# a hash to store the key/value pairs for each queue manager
my %conf = ();
while (<DATA>) {
# see if we have a new "queuemanager" line and if there's any data
+to save
if ( /^QueueManager/ && %conf ) {
# save what we have already stored
push @queue_managers, { %conf };
# clear the hash for the next one
%conf=();
next;
}
# now check key/value pair lines and if we've got one, put its
# data into the hash. I'm assuming that values are bracketed by
# spaces, so I just grab the longest set of non-spaces
if ( my ($key, $value ) = /^\s*(\w+)\s*=\s*(\S+)/ ) {
$conf{$key} = $value;
}
}
# ahh, the last entry probably hasn't been saved
push @queue_managers, {%conf} if %conf;
What this does is put each configuration entry, stored as a hash reference, into an array. If you just want to print the darn thing out, you could print out the hash instead of push ing an anonymous copy (which is what the { %conf } syntax does) onto the array.
What this code gives you is an array, each of whose members corresponds to one of the "QueueManager" entries (where that means, "follows a QueueManager line and ends at a new QueueManager line or the end of the file, whichever comes first).
Managing to do something with this data structure, or changing it to a diffferent kind of structure (it strikes me that what you'd really like if you're using this as a config file is a hash of hashes, where the key of each hash is the name of the queue manager, and whose values are the other values.) is something I'll let you figure out for yourself, with a tip of the hat to References quick reference, perlref, perllol, and perldsc.
HTH and good luck!
If not P, what? Q maybe?
"Sidney Morgenbesser"
-
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.