Use Getopt::Long, it has a lot more capabilities and is 'use strict' clean.
Here's an example of my boilerplate.  Note that I always include a '-h'
option to refresh my memory of the command's syntax.  Run 'perldoc
Getopt::Long' for details.

# 010313 Mac First version...
$VERSION = '1.0000';

use Getopt::Long;

use strict;
use vars qw( $VERSION );

# Set default initial values
my $sInst    = $ENV{'TWO_TASK'} || $ENV{'ORACLE_SID'} || 'def_instance';
my $sOwner   = 'owner';
my $sUidPwd  = 'uid/pwd';

# Syntax description
sub usage {
   my ( $sOpt, $sVal, @sMsg ) = @_;

   my $sHelpText = <<END_HELP_END;
What this program does
syntax: $RealScript [opt] arg [arg]
Opt: ($VERSION)
   -i inst  = Instance ($sInst)
   -o owner = Schema owner ($sOwner)
   -u user  = Userid[/Password] to use ($sUidPwd)
Arg:
   Arg = An argument
Out: Progress to STDOUT
END_HELP_END
# Balance quotes in here document # ' # "

   my $nRet = 'help' eq $sOpt ? 0 : 0 + $sVal;
   select STDERR if $nRet;
   foreach ( @sMsg, $sHelpText ) { s/\s+$//; print "$_\n"; }
   exit $nRet;
}

# Parse command line for options
Getopt::Long::config( qw( no_ignore_case no_auto_abbrev require_order ) );
GetOptions(
   'inst|i=s'   => \$sInst,
   'own|o=s'    => \$sOwner,
   'user|u=s'   => \$sUidPwd,
   'help|h' => \&usage ) or usage( 'die', 1 );

--
Mac :})
** I normally forward private database questions to the DBI mail lists. **
Give a hobbit a fish and he'll eat fish for a day.
Give a hobbit a ring and he'll eat fish for an age.
----- Original Message -----
From: "Loo, Peter # PHX" <[EMAIL PROTECTED]>
To: "'Michael A. Chase'" <[EMAIL PROTECTED]>; "Peter Loo"
<[EMAIL PROTECTED]>; "Loo, Peter # PHX" <[EMAIL PROTECTED]>;
<[EMAIL PROTECTED]>
Sent: Tuesday, March 13, 2001 9:17 AM
Subject: RE: Stored Procedure (arguments)


> I am trying to use getopt.pl, however, it give me errors and terminate
when
> I use 'use strict;'.
>
> aztec:/usr/local/apps/sma/devl/bin>runAgg_TAlgnRxTerrSpcltDrugPlan.pl
>
> Loading DB routines from perl5db.pl version 1.0402
> Emacs support available.
>
> Enter h or `h h' for help.
>
> Global symbol "$opt_s" requires explicit package name at sma_run_aggs.pl
> line 53.
> Global symbol "$opt_l" requires explicit package name at sma_run_aggs.pl
> line 53.
> Global symbol "$opt_c" requires explicit package name at sma_run_aggs.pl
> line 73.
> Global symbol "$opt_t" requires explicit package name at sma_run_aggs.pl
> line 75.
> Global symbol "$opt_d" requires explicit package name at sma_run_aggs.pl
> line 76.
> Global symbol "$opt_m" requires explicit package name at sma_run_aggs.pl
> line 77.
> Execution of sma_run_aggs.pl aborted due to compilation errors.
> Debugged program terminated.  Use q to quit or R to restart,
>   use O inhibit_exit to avoid stopping after program termination,
>   h q, h R or h O to get additional info.
>
> This is how I call getopt.pl:
>
>
>   use strict;
>   use Cwd;
>   use DBI;
>   require "getopt.pl";
>
>   Getopt('sl:ctdm');

# Here's how I'd do it
my ( $s, $l, $c, $t, $d, $m );
Getopt::Long::config( qw( no_ignore_case no_auto_abbrev require_order ) );
GetOptions(
   'sthing!'   => \$s, 's!' => \$s, # Use either -sthing or -s
   'lthing|l=s'    => \$l, # Use either -lthing string or -l string
   'cthing!'   => \$c, 'c!'   => \$c, # Can use 'cthing|c!' in recent
Getopt::Long
   'tthing!'   => \$t, 't!'   => \$t,
   'dthing!'   => \$d, 'd!'   => \$d,
   'mthing!'   => \$m, 'm!'   => \$m,
   'help|h' => \&usage ) or usage( 'die', 1 );



Reply via email to