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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |