Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask

Re: Constructing hashes

by rovf (Priest)
on Jun 05, 2013 at 08:02 UTC ( #1037159=note: print w/replies, xml ) Need Help??

in reply to Constructing hashes

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 <>

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1037159]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (None)
    As of 2021-10-16 03:36 GMT
    Find Nodes?
      Voting Booth?
      My first memorable Perl project was:

      Results (69 votes). Check out past polls.