Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
Great code for an intern ! (++)

If you want to put some effort into making it more professional looking, I'd suggest data-driven parameter processing. This would minimize repeated code, standardize the look, make it extensible, and many other "good" buzzwords.

To do that, you would need to come up with a structure like:

my %params=( host => (TYPE=>"s", REQUIRED=>1, VALUE=>undef, VALIDATE=>sub { # Tis could be a subref to an external, if +it gets too big my $host=shift; print "\nChecking if $host is alive.. \n"; $ping = Net::Ping->new(); if ($ping->ping($host)){ print "$host is alive\n\n"; }else { print "$host is unreachable\n\n"; exit; } $ping->close(); }, ), # End of host engine => (TYPE=>"s", REQUIRED=>1, VALUE=>undef,), user => (TYPE=>"s", REQUIRED=>1, VALUE=>undef), password => (TYPE=>"s", REQUIRED=>1, VALUE=>undef), );
Then you can process it like this:
GetOptions( map { "$_=$params{$_}{TYPE}" => \$params{$_}{VALUE} } keys %params ); for (keys %params){ showUsage("Missing required parameter $_") if $params{$_}{REQUIRED} +&& ! $params{$_}{VALUE}; $params{$_}{VALIDATE}->($params{$_}{VALUE}) if $params{$_}{VALIDA +TE}; }

             "I'm fairly sure if they took porn off the Internet, there'd only be one website left, and it'd be called 'Bring Back the Porn!'"
        -- Dr. Cox, Scrubs


In reply to Re: Review of my script by NetWallah
in thread Review of my script by Jackiejarvis

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 examining the Monastery: (4)
As of 2024-04-24 13:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found