Aside from a few harmless, but unlogical parts of your programs (for example, why do you chomp $_ when you already know that it can't end with a newline), I don't find that you clearly expressed your problem, so I have to guess a bit:
The listing you write under "Example" is what should end up in the logfile, right?
In this case, you just need to remember, whether you have already printed the server name for the logfile. Each server causes in several lines being printed (one line for each component), but only the first line will also contain the server name. I would therefore write your print statement in the following way:
print "$server_name_or_blank $RM\n";
and make sure that on the first iteration of the inner loop, $server_name_or_blank contains the name of the server, and on subsequent iterations of the inner loop it contains a string of spaces, of the same length the server name had been.
A few additional remarks: First, always have "use strict; use warnings;" in your program. Second, I strongly advice against using $_ as a variable for the outer loop. There are many cases where Perl operations implicitly modify $_. Finally, don't modify the loop variable, unless you really know what you are doing; the loop variable is an alias to the respective list element, and by changing the variable, you also change the list element. Though this is harmless in your particular case, you will be bitten sooner or later, if you continue this practice.
--
Ronald Fischer <ynnor@mm.st>
-
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.
|