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

Discussion in 'Perl Misc' started by mothra, Dec 2, 2004.

  1. mothra

    mothra Guest

    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
     
    mothra, Dec 2, 2004
    #1
    1. Advertising

  2. On Thu, 02 Dec 2004 07:48:03 -0800, mothra wrote:

    > 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
     
    James Willmore, Dec 2, 2004
    #2
    1. Advertising

  3. mothra

    Paul Lalli Guest

    "mothra" <> wrote in message
    news:41af3914$...
    > 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
     
    Paul Lalli, Dec 2, 2004
    #3
  4. mothra

    Shawn Corey Guest

    Re: Having problems parsing command line options using Getopt::Longon windows

    mothra wrote:
    > 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
     
    Shawn Corey, Dec 2, 2004
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. veryhotsausage
    Replies:
    1
    Views:
    1,898
    veryhotsausage
    Jul 4, 2008
  2. Sunil
    Replies:
    5
    Views:
    365
    Bart Lateur
    Aug 14, 2003
  3. Sunil
    Replies:
    8
    Views:
    163
    Benjamin Goldberg
    Sep 2, 2003
  4. nahum_barnea
    Replies:
    3
    Views:
    143
    Peter Makholm
    Sep 21, 2010
  5. Ganesh Pal
    Replies:
    0
    Views:
    119
    Ganesh Pal
    Feb 25, 2014
Loading...

Share This Page