#!/usr/local/bin/perl -w use strict; use English; use diagnostics; use vars qw($opt_h $opt_v); use Getopt::Std; # Copyright UTC -Eric Hanson ## This program ## Usage: ### Usage Checking # Checking for 3 args - NOTE that $#ARGV starts at 0 #if( $#ARGV > 2 or $#ARGV < 2 ){ # exit(0); #} ### Varables my $VERSION = " -eh"; my $DEBUG = 0; ### Argument Checking # Get the opts getopts("hv"); # Print help if necescary if ( $opt_h ){ print_help(); exit; } # Show help done now # Set up debug if verbose if( $opt_v ){ $DEBUG = 1; } ### Varable Checking # Show vars ########################################### ### Main ## Note debug with a section is indented one space ## and has a dash in front of it. ## Casual feedback is prefaced with a '|' and 2x Indent ## Important items are 2 x indented and have a '+' in front ## Subroutines are started with a '=>' sinle indent print "Main Program Logic = Verbose (Debug) mode!\n" if $DEBUG; print "\nFinished!\n" if $DEBUG; exit; # Should have a return code here! ########################################### ### Subroutines ## Handy code: print "=> Inside sub: line ".__LINE__." \n" if $DEBUG; ################################## ## ## ARGS: ## RETURNS: sub my_template { print "=> Inside sub my_template: line ".__LINE__." \n" if $DEBUG; # Vars #Sub Main return 1; # Changer return code as needed } # end of sub template ######################### sub print_help { print "This should have a usefull line here!\n"; return 1; } ## This is an end of subroutine and an error messaging tool # Used in subroutines. usefull for creating a trace ## ARGS1: Error message to print ## ARGS+: Additional info sub failed { my $error1 = join("\n",@_); # Getting the first Error print "! $error1\n"; return 0; } # End of sub failed ################################## ## This sub should exit the program gracefully by doing any cleanup ## necescary, as well as providing some usefull error messages. # Used from main: or end_and_exit(""); ## ARGS1: Error Message you pass in ## ARGS2: Error message from perl ( $! or $@ ) If not passed ## in the sub will use $! which may have changed (or not) sub end_and_exit { my $error1 = shift(@_); # Getting the first Error my $error2; if (@_){$error2 = join(' ',@_);} # Get rest, if passed in else {$error2 = $!;} ## Print out stuff print "\n! Error during execution:\n"; print "! $error1\n$error2\n"; ## Clean up clean_up(); exit 1; # Error to system } # End of end_and_exit ## Cleans up doing anything else that ## needs to be done. sub clean_up { return 1; # REturn code } # End of clean up sub.