develooper Front page | perl.beginners | Postings from January 2002

Getopt::Long problem (Allegedly)

Thread Next
From:
Angus Laycock
Date:
January 30, 2002 13:45
Subject:
Getopt::Long problem (Allegedly)
Message ID:
01d701c1a9d7$af993240$b154ac3e@mralaycock
Hi,

I wrote this today on UNIX . When I tested the script, calling it with all the options (f s D P U S e q ) the "-s" option would not return the value from the command line. All the other variables got populated. I then change the "s:s" to "f:s" and that worked. I am trying to replace some software which uses -s as an option and need to handle the options the same in the PERL replacement. Is there a bug with "s:s"?

use Getopt::Long;
my $DATABASE  = ""; 
my $PASSWORD  = "";
my $USER = "";
my $SERVER = "";
my $ERR  = ""; 
my $SPROC = "";
my $QUERY = "";   
my $TT  = "";
GetOptions ( 'f:s' => \$TT, 's:s' => \$SPROC, 'D:s' => \$DATABASE,'P:s' => \$PASSWORD, 
  'U:s' => \$USER, 'S:s' => \$SERVER,'e' => \$ERR,'q:s' => \$QUERY) 
  || die "Options incorrect\n";

print "DATABASE =  $DATABASE\n PASSWORD = $PASSWORD\n USER = $USER\n  SERVER = $SERVER\n 
 ERR = $ERR\n  SPROC = $SPROC\n  QUERY = $QUERY\n  TT = $TT\n";
exit 0;


I have just tried it at home and using "-s" and "-S" to try and replicate at home on ActivePerl but it puts the options in the -S variable, not in "-s"


C:\Perl\scripts>perl getopt_test1.pl -s sausage -S slow
  DATABASE =
 PASSWORD =
 USER =
 SERVER = slow
 ERR =
 SPROC =
 QUERY =

I have now changed to using getopts which works but am curious why using Getopt::Long doesn't like the -s option.

Help please

Thanks in  Advance

Gus



Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About