When starting a new script, you can use this template as a base which consists of:
- RCS, CVS or SVN "Id" keyword to keep the version information.
- Support script arguments.
- Show usage function.
- A trim function.
#!/usr/bin/perl -w
# $Id: $
#
use strict;
use Getopt::Long;
my $VERSION = "1.0";
my %option;
die unless GetOptions(
"help" => \$option{'help'},
);
if (defined( $option{'help'} )) {
print_usage();
}
...
# Perl trim function to remove whitespace from the start and end of the string
sub trim {
my $string = shift;
$string =~ s/^\s+//;
$string =~ s/\s+$//;
return $string;
}
# Print usage
sub print_usage {
my $usage = <<EOF;
DESCRIPTION:
OPTIONS:
--[h]elp Show this help text.
EXAMPLE:
\$ $0
EOF
die($usage);
}
No comments:
Post a Comment