Skel.pl

From PeformIQ Upgrade
Revision as of 16:46, 4 September 2009 by PeterHarding (talk | contribs) (Created page with '=Skeleton PERL Script= <pre> $ cat skel.pl #!/usr/bin/env perl #--------------------------------------------------------------------------- require Getopt::Std; #------------...')
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
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()

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