Getopt::Long and bundling.

Discussion in 'Perl Misc' started by Todd Aceman, Oct 26, 2003.

  1. Todd Aceman

    Todd Aceman Guest

    Hi folks.

    Perhaps i'm being stupid about this, but can you tell me why this
    isn't working...

    I have a script called "x.pl", that's using Getopt::Long. The script
    looks like this:

    #!/usr/bin/perl
    use Getopt::Long;
    GetOptions (
    "debug" => \$debug,
    "silent" => \$silent );
    print "DEBUG: $debug\n";
    print "SILENT: $silent\n";

    When i run this using "./x.pl --debug", As expected, i get the
    following response:

    % ./x.pl --debug
    DEBUG: 1
    SILENT:

    When i run this using "./x.pl -d", i get the same response:

    % ./x.pl -d
    DEBUG: 1
    SILENT:

    So far, so good...

    However, if i turn on bundling using "Getopt::Long::Configure (
    'bundling' );", so that the script now reads:

    #!/usr/bin/perl
    use Getopt::Long;
    Getopt::Long::Configure ( "bundling" );
    GetOptions (
    "debug" => \$debug,
    "silent" => \$silent );
    print "DEBUG: $debug\n";
    print "SILENT: $silent\n";

    And i try "./x.pl -ds", i get the following response:

    % ./x.pl -ds
    Unknown option: ds
    DEBUG:
    SILENT:

    If i try just a single "-d" paramter, i still get an error:

    % ./x.pl -d
    Unknown option: d
    DEBUG:
    SILENT:

    From reading the docs for Getopt::Long, it talks about bundling and
    says that

    For example, when vax, a, v and x are all valid options,

    -vax

    would set a, v and x...

    However, when i try it. it doesn't work. Can someone tell me why
    when i turn on "bundling", it stops accepting any parameters with a
    single dash ("-") character?

    This is perl 5.8.0 on Redhat Linux 9 (standard RPM distribution), and
    also perl 5.8.0 on Windows XP using cygwin (the standard cygwin
    distribution).

    Thanks very much.

    --tka.
     
    Todd Aceman, Oct 26, 2003
    #1
    1. Advertising

  2. Todd Aceman

    ko Guest

    Todd Aceman wrote:

    [snip]

    > However, if i turn on bundling using "Getopt::Long::Configure (
    > 'bundling' );", so that the script now reads:
    >
    > #!/usr/bin/perl
    > use Getopt::Long;
    > Getopt::Long::Configure ( "bundling" );
    > GetOptions (
    > "debug" => \$debug,
    > "silent" => \$silent );
    > print "DEBUG: $debug\n";
    > print "SILENT: $silent\n";
    >
    > And i try "./x.pl -ds", i get the following response:
    >
    > % ./x.pl -ds
    > Unknown option: ds
    > DEBUG:
    > SILENT:
    >
    > If i try just a single "-d" paramter, i still get an error:
    >
    > % ./x.pl -d
    > Unknown option: d
    > DEBUG:
    > SILENT:
    >
    > From reading the docs for Getopt::Long, it talks about bundling and
    > says that
    >
    > For example, when vax, a, v and x are all valid options,
    >
    > -vax
    >
    > would set a, v and x...
    >
    > However, when i try it. it doesn't work. Can someone tell me why
    > when i turn on "bundling", it stops accepting any parameters with a
    > single dash ("-") character?


    Right before the part you quoted from the docs:

    "Configured this way, single-character options can be bundled but long
    options must always start with a double dash -- to avoid abiguity."

    So you could use './x.pl --d --s', shorten the options to a single
    character, or use an alias with a single dash:

    GetOptions ( # now './x.pl -ds' will work
    "debug|d" => \$debug,
    "silent|s" => \$silent );

    [snip]

    HTH - keith
     
    ko, Oct 26, 2003
    #2
    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. Tom Parson
    Replies:
    2
    Views:
    495
    Bjorn Abelli
    May 22, 2006
  2. Mathieu Dutour

    long long and long

    Mathieu Dutour, Jul 17, 2007, in forum: C Programming
    Replies:
    4
    Views:
    497
    santosh
    Jul 24, 2007
  3. Alan Fisher

    Signing and bundling data using certificates

    Alan Fisher, Jun 17, 2005, in forum: ASP .Net Security
    Replies:
    5
    Views:
    200
  4. Joel VanderWerf

    getopt/long and ARGV

    Joel VanderWerf, Nov 12, 2006, in forum: Ruby
    Replies:
    0
    Views:
    141
    Joel VanderWerf
    Nov 12, 2006
  5. Daniel Berger

    Getopt::Long and <> problem

    Daniel Berger, Feb 18, 2004, in forum: Perl Misc
    Replies:
    3
    Views:
    263
    Daniel Berger
    Feb 19, 2004
Loading...

Share This Page