Getopt::Long and bundling.

T

Todd Aceman

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.
 
K

ko

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
 

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

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top