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>

In reply to Re: Constructing hashes by rovf
in thread Constructing hashes by Mark.Allan

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.