Having problems parsing command line options using Getopt::Long on windows

M

mothra

Hi All,

I am having problems parsing command line options using Getopt::Long.
It would seem that this module will only process the first option. This
only happens on the windows platform. Here is a simple script that will
demonstrate my problem.

#!/app/bin/perl
use strict;
use warnings;
use Getopt::Long;

my %options;

my $success = GetOptions ( \%options, 'sd=s', 'ed=s' );
print "$_ -> $options{$_}\n" foreach( keys %options );

print Getopt::Long::VersionMessage();

output: (on windows)
F:\scripts>my.pl --sd=01/01/2004 --ed=02/09/2004
sd -> 01/01/2004
F:\scripts\my.pl
(Getopt::Long::GetOptions version 2.34_02; Perl version 5.8.3)

F:\scripts>

I tried this same script on HPUX 11.11
output: (HPUX)
$ ./my.pl --sd=01/01/2004 --ed=02/09/2004
ed -> 02/09/2004
sd -> 01/01/2004
../my.pl
(Getopt::Long::GetOptions version 2.34_02; Perl version 5.8.0)
$

Can someone else (that is using windows) try this simple script to see if
the problem can be reproduced?

Thanks

Mothra
 
J

James Willmore

I am having problems parsing command line options using Getopt::Long.
It would seem that this module will only process the first option. This
only happens on the windows platform. Here is a simple script that will
demonstrate my problem.

#!/app/bin/perl
use strict;
use warnings;
use Getopt::Long;

my %options;

my $success = GetOptions ( \%options, 'sd=s', 'ed=s' );
print "$_ -> $options{$_}\n" foreach( keys %options );

print Getopt::Long::VersionMessage();

output: (on windows)
F:\scripts>my.pl --sd=01/01/2004 --ed=02/09/2004
sd -> 01/01/2004
F:\scripts\my.pl
(Getopt::Long::GetOptions version 2.34_02; Perl version 5.8.3)

F:\scripts>
Can someone else (that is using windows) try this simple script to see if
the problem can be reproduced?

According to the documentation, one troubleshooting option is to place the
following before any usage of Getopts

print STDERR (join("│",@ARGV),"\n");

This will show how the command line options are being passed. This, in
turn, shows you what the script "thinks" it sees. Which, in turn, might
produce a solution (think quoting).

All of this is just a semi-educated guess :)

HTH

Jim
 
P

Paul Lalli

mothra said:
I am having problems parsing command line options using Getopt::Long.
It would seem that this module will only process the first option. This
only happens on the windows platform. Here is a simple script that will
demonstrate my problem.

#!/app/bin/perl
use strict;
use warnings;
use Getopt::Long;

my %options;

my $success = GetOptions ( \%options, 'sd=s', 'ed=s' );
print "$_ -> $options{$_}\n" foreach( keys %options );

print Getopt::Long::VersionMessage();

output: (on windows)
F:\scripts>my.pl --sd=01/01/2004 --ed=02/09/2004
sd -> 01/01/2004
F:\scripts\my.pl
(Getopt::Long::GetOptions version 2.34_02; Perl version 5.8.3)

Can someone else (that is using windows) try this simple script to see if
the problem can be reproduced?

On Windows 2000 Professional:

C:\DOCUME~1\ADMINI~1>opts.pl --sd=01/01/2004 --ed=02/09/2004
ed -> 02/09/2004
sd -> 01/01/2004
C:\DOCUME~1\ADMINI~1\opts.pl
(Getopt::Long::GetOptions version 2.34; Perl version 5.8.3)

I copy & pasted your script exactly to produce those results...

Paul Lalli
 
S

Shawn Corey

mothra said:
output: (on windows)
F:\scripts>my.pl --sd=01/01/2004 --ed=02/09/2004
sd -> 01/01/2004
F:\scripts\my.pl
(Getopt::Long::GetOptions version 2.34_02; Perl version 5.8.3)

On some versions of MS DOS a trailing slash means a switch, MS word for
option. Try:

my.pl --sd="01/01/2004" --ed="0209/2004"

--- Shawn
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,815
Latest member
treekmostly22

Latest Threads

Top