Re: Getopt::Long problem (Allegedly)

2002-01-30 Thread Briac Pilpré

On Wed, 30 Jan 2002 21:47:15 -, Angus Laycock wrote:
> --=_NextPart_000_01D4_01C1A9D7.AEC826A0
> Content-Type: text/plain;
>   charset="iso-8859-1"
> Content-Transfer-Encoding: quoted-printable
> 
> 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"?
> 

By default, Getopt::Long is case insensitive. Try adding the "bundling"
and "ignore_case" options.

cf perldoc Getopt::Long (Configuring Getopt::Long)

#!/usr/bin/perl -w
use strict;
use Getopt::Long qw(GetOptions);
Getopt::Long::Configure ("bundling", "ignore_case");

my($DATABASE, $PASSWORD, $USER, $SERVER, $ERR, $SPROC, $QUERY, $TT)
=('')x8;

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 <<"_EOT_";
DATABASE = $DATABASE
PASSWORD = $PASSWORD
USER = $USER
SERVER   = $SERVER
ERR  = $ERR
SPROC= $SPROC
QUERY= $QUERY
TT   = $TT
_EOT_

__END__
-- 
briac
 << dynamic .sig on strike, we apologize for the inconvenience >>


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Getopt::Long problem (Allegedly)

2002-01-30 Thread Angus Laycock

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