![]() | |
![]() |
![]() |
![]() | |
![]() | |
Template for Perl Programs | |
![]() |
#!/usr/bin/perl use strict; use warnings; use diagnostics; use POSIX; my $title= "@ARGV"; my $date= localtime(); my $year= (split ' ',$date)[4]; my $author= "$^O user"; if ($^O =~ /mswin/i) { $author= $ENV{USERNAME} if defined $ENV{USERNAME}; } else { my $userid= POSIX::cuserid(); $author = (getpwnam($userid))[6]; } my $template= <<'EOF'; #!PERL_FULLPATH_TEMPLATE_ITEM #!PERL_FULLPATH_TEMPLATE_ITEM -d:ptkdb # # AUTHOR_TEMPLATE_ITEM # DATE_TEMPLATE_ITEM # # TITLE_TEMPLATE_ITEM # use vars qw($VERSION); $VERSION=".01"; use strict; use warnings; use diagnostics; use Getopt::Long; use Pod::Usage; my $opt_debug = 0; my ($opt_help, $opt_man, $opt_versions); GetOptions( 'debug=i' => \$opt_debug, 'help!' => \$opt_help, 'man!' => \$opt_man, 'versions!' => \$opt_versions, ) or pod2usage(-verbose => 1) && exit; pod2usage(-verbose => 1) && exit if ($opt_debug !~ /^[01]$/); pod2usage(-verbose => 1) && exit if defined $opt_help; pod2usage(-verbose => 2) && exit if defined $opt_man; # # # # # # # # END{ if(defined $opt_versions){ print "\nModules, Perl, OS, Program info:\n", " Pod::Usage $Pod::Usage::VERSION\n", " Getopt::Long $Getopt::Long::VERSION\n", " strict $strict::VERSION\n", " Perl version $]\n", " Perl executable $^X\n", " OS $^O\n", " $0\n", "\n\n"; } } =head1 TITLE TITLE_TEMPLATE_ITEM =head1 SYNOPSIS =head1 DESCRIPTION =head1 ARGUMENTS Place --help print Options and Arguments --man print complete man page =head1 OPTIONS --versions print Modules, Perl, OS, Program info --debug 0 don't print debugging information (default) --debug 1 print debugging information =head1 LICENSE This software is released under the same terms as perl itself. If you don't know what that means visit http://perl.com/ =head1 AUTHOR Copyright (C) AUTHOR_TEMPLATE_ITEM YEAR_TEMPLATE_ITEM All rights reserved =cut EOF $template=~ s/DATE_TEMPLATE_ITEM/$date/g; $template=~ s/TITLE_TEMPLATE_ITEM/$title/g; $template=~ s/PERL_FULLPATH_TEMPLATE_ITEM/$^X/g; $template=~ s/AUTHOR_TEMPLATE_ITEM/$author/g; $template=~ s/YEAR_TEMPLATE_ITEM/$year/g; print $template;