Skel.pl

From PeformIQ Upgrade
Jump to navigation Jump to search

Skeleton PERL Script

$ cat skel.pl
#!/usr/bin/env perl

#---------------------------------------------------------------------------

require Getopt::Std;

#---------------------------------------------------------------------------

$usage = qq(\
Usage:

   # skel.pl [-d] [-f <file>] [-v]

);

#---------------------------------------------------------------------------

my %opts      = ();
my $debug_lvl = 0;

#---------------------------------------------------------------------------

sub getargs
{
   Getopt::Std::getopts('dD:vf:h', \%opts);

   for my $opt (keys(%opts)) {
      if ($opt eq 'd') {
         $debug_lvl++;
         next;
      }

      if ($opt eq 'D') {
         $debug_lvl = $opts{D};
         next;
      }

      if ($opt eq 'h') {
         printf("%s\n", $usage);
         exit(0);
         next;
      }
   }
}  # getargs

#---------------------------------------------------------------------------

sub main
{
   getargs();

   if (defined($opts{f})) {
      printf("file -> %s\n", $opts{f});
   }

   if ($debug_lvl > 0) {
      printf("Debug Level = %d\n", $debug_lvl);
   }
}

#---------------------------------------------------------------------------

main()

#---------------------------------------------------------------------------