Scripting

Perl Script Template with basic logging functions

#! perl
#===============================================================================
# Objective:
# ----------
# 
# Sample Perl script template with basic logging functions
#
#
# $Header: $
#===============================================================================
# Include Modules
#===============================================================================
use strict;
use warnings;
use Pod::Usage;
use Getopt::Long qw(:config no_ignore_case bundling);
#===============================================================================
# Global Variables Declaration
#===============================================================================
use vars qw($DEBUG);
#===============================================================================
# Prototypes Section
#===============================================================================
sub DoAction;
sub InitGlobals;
sub ProcessArgs;
sub Info   {my ($mesg) = @_; print "INFO: $mesg\n";}
sub MyErr  {my ($mesg) = @_; print "ERROR: $mesg\n"}
sub MyWarn {my ($mesg) = @_; print "WARNING: $mesg\n";}
sub MyDie  {my ($mesg) = @_; print "ERROR: $mesg\n"; exit(1);}
sub Debug  {my ($mesg) = @_; print "DEBUG: $mesg\n" if $DEBUG;}
#===============================================================================
# main()
#===============================================================================
{
    InitGlobals();
    ProcessArgs();
    DoAction();
    exit(0);
}
#===============================================================================
# sub InitGlobals
#===============================================================================
sub InitGlobals {
}
#===============================================================================
# sub ProcessArgs
#===============================================================================
sub ProcessArgs {
    Getopt::Long::Configure("bundling", "no_ignore_case");
    if (! GetOptions('D'   => \$DEBUG,
                     'h|?' => sub { &pod2usage(-verbose => 2)}) || @ARGV ) {
        pod2usage(2);
    }
}
#===============================================================================
# sub DoAction
#===============================================================================
sub DoAction {
}
#===============================================================================
# documentation
#===============================================================================
__END__
=head1 NAME
B<.pl> - .
=head1 SYNOPSIS
.pl [- <>][-h] [-D]
=head1 OPTIONS
=over 4
=item B<-D>
Run in debug mode.
=item B<-> <>
=item B<-h>
Print this help message.
=back

Advertisements