Re: Here is my Perl "skeleton" (starter) script (what do you use?)



X-Ftn-To: usenet@xxxxxxxxxxxxxxx

>I'm always looking for improvements. But I thought my script was
>pretty good (most of it was taken straight from the perldocs of the

You can separate some of your init routines into module, and call them only
when you actually need them, eg.

my $dbh = $cfg{dbi} && YourModule::DBIconnect($cfg{dbi});
It also saves you time when in need for multiple db connections.

The same goes for sftp; you could be connecting to something even when you
don't have parameters in $cfg{'sftp'}.


>#use diagnostics; ##
> ##
>### Other skeleton stuff needs these... check before you delete ##
>use English; #for (English) readability ##

English module has unfortunate defaults so it adds some overhead, but this
is easily "fixed" if you don't need some of costly regex features.
==========
SYNOPSIS
use English qw( -no_match_vars ) ; # Avoids regex performance penalty


>my %cfg; ##
> ##
>eval {no strict 'vars'; #in case the GetOpts block was deleted ##
> $cfg{'inifile'} = $opt{'config'} # if defined $opt{'config'} ##
> || ("$FindBin::Bin/$FindBin::Script" =~ /(.*)\.pl/)[0].'.ini'; ##
>}; ##

I guess you don't actually need eval as you're not inspecting $@ after it,
so pure block with "no strict 'vars'" better reflects real intention.


>####################################################################
>######### VALIDATE ###### VALIDATE ###### VALIDATE ##########
>####################################################################
>do{ #use 'do' to lexically isolate variables ##

nothing wrong here, you can also drop "do" and use pure block (btw, from
which you can exit at any point).

MY_BLOCK: {
...
last MY_BLOCK if ...;
...
}
>my $ps = "/usr/bin/ps"; #crude, but it works for my purposes ##
>die "Already Running\n" if scalar grep(/perl.*$0/, `$ps -ef`) >1; ##
> ##
>-e && unlink for keys %{$cfg{'killfile'}}; #remove old killfiles ##

unlink grep -e, keys %{$cfg{killfile}};

more style related; "for" modifier is nice but it can also grow too much and
kill initial simplicity.



--
Matija
.