Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

comment on

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

You can create a hash with your globals and have Getopt override them if needed.

use Getopt::Long; sub get_options { my $def = shift; my $cur = {}; $cur->{$_->[0]} = $_->[2] for @$def; my @def = map {$_->[0].$_->[1]} @$def; GetOptions( $cur, @def ); return $cur; } my $defaults = [ [ debug => '' => 0 ], [ help => '' => 0 ], [ interactive => '' => 0 ], [ host => '=s' => '999.999.999' ], [ username => '=s' => 'username' ], [ home => '=s' => $ENV{HOME} ], # ... ]; my $opt = get_options( $defaults ); # if ( $opt->{help} ) { ... } # foo( $opt->{host} );

You loose strict being able to catch your typo's but it becomes real easy to add new options/variables.

Some refactoring wouldn't hurt...

sub debug { my $msg = shift; writeLog( $msg ) if $opt->{debug}; } sub timestamp { my $when = shift || time; my ( $sec, $min, ... ) = localtime( $when ); # ... return $stamp; }

You might benefit from placing some of your comments into POD format.

There are places you might be able to do something like:

# ... my @k = ( 'Status', 'Time Stamp', 'Value', 'Error Message' ); my $h = $HoHoHoA{$line_number_being_processed}; $one_line_summary = $h->{shift(@k)} . 'No Error. '; $one_line_summary .= $h->{$_} . '. ' for @k; $one_line_summary .= "$j.";

In general, when you see lot's of lines that look the same except for one or two differences there's probably a way to clean it up and make it easier to add one more thing without copying a line from above and changing that one different thing.

Just a personal thing, when processing hash keys i usually transform them into all lower case and change whitespace to '_' so i don't have to quote them as often.

my @k = qw/ status time_stamp value error_message /;

Which just saves a bit of typing here and there.

Otherwise, if it does what you want it to do...


In reply to Re: Seek Critique of SFTP program, format, structure, overall "Perl"ness by zengargoyle
in thread Seek Critique of SFTP program, format, structure, overall "Perl"ness by mikedshelton

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 learning in the Monastery: (4)
As of 2024-04-26 04:43 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found