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



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