Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

A couple of thoughts

Since it appears that the data you are interested in is always in the same offsets of your split you could define them once, and then use them throught out the rest of the code. (You could also use Constant, but read up on the docs and do a super search, as interesting problems can arise from using the module). You could use the select function to clean up the prints, or a HERE document. If you end up going with HERE docs, I would suggest doing whatever "extra" logic prior to, so that you don't need to end the print, perform a simple test and reinitiate printing.. Ala

# snipped for brevity's sake my $nodename = '0'; my $m_type = '2'; my $comment = '6'; # etc... for ( @MASTER ) { my($chk_cmd, $chk_ping); chomp; my $line = [ split("\t") ]; # If its a t3 array these lines need to be different, do it # now as opposed to later if ( $line->[$m_type] eq 'sun_t3') { $chk_cmd = "check_command\tcheck-host-alive-ping\n"; $chk_ping = "check_command\tcheck_ping\n"; } else { $chk_cmd = "check_command\tcheck-host-alive\n"; $chk_ping = "check_command\tcheck_newping\n"; } print autoconf<<EOF; # Host $line->[$nodename] $line->[$m_type] check host alive define host { use generic-host host_name $line->[$nodename] alias $line->[$comment] address $IPnumber $chk_cmd } EOF }

Also since quite a bit of that content is relativly static, I might end up using an array to store bits and pieces, then joining them into single scalars ala my $out = join("\n", @data); to further clean up the output.

use perl;


In reply to Re: Better use of perl print statment for Nagios, (Long) by l2kashe
in thread Better use of perl print statment for Nagios by emjga1

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • 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.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (7)
As of 2024-04-19 07:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found