Skip Menu |

Preferred bug tracker

Please visit the preferred bug tracker to report your issue.

This queue is for tickets about the Getopt-Long-Descriptive CPAN distribution.

Report information
The Basics
Id: 57503
Status: resolved
Priority: 0/
Queue: Getopt-Long-Descriptive

People
Owner: Nobody in particular
Requestors: David.Biesack [...] sas.com
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: (no value)



Subject: Getopt::Long::Descriptive usage question
Date: Fri, 14 May 2010 23:49:27 -0400
To: bug-getopt-long-descriptive [...] rt.cpan.org
From: "David J. Biesack" <David.Biesack [...] sas.com>
Thanks for your Getopt::Long::Descriptive module. I have a quick question: when I use the '@' option for multiple args: my ($commandLine, $usage) = describe_options ( '%c %o command [commands...]', [ 'java-opt|j:s@', "Java runtime options"], ); @java_opt = $commandLine->java_opt(); then invoking with mycmd -j a -j b -j c the call $commandLine->java_opt(); returns an ARRAY object, not a list of the values. That is, after @java_opt = $commandLine->java_opt(); printf("@java_opt , last is %d, elt 0 is %s\n", $#java_opt, $java_opt[0]); this prints as ARRAY(0x109a9db0) , last is 0, elt 0 is ARRAY(0x109a9db0) How do I get to the elements, i.e. each of the values from the command line? (The Getopt::Long module works and returns a decomposable array, but lacks the features of Getopt::Long::Descriptive.) thanks for any help, djb -- David J. Biesack, SAS SAS Campus Dr. Cary, NC 27513 www.sas.com (919) 531-7771
Subject: Re: [rt.cpan.org #57503] Getopt::Long::Descriptive usage question
Date: Sat, 15 May 2010 07:50:55 -0400
To: "David J. Biesack via RT" <bug-Getopt-Long-Descriptive [...] rt.cpan.org>
From: Ricardo Signes <rjbs [...] cpan.org>
* "David J. Biesack via RT" <bug-Getopt-Long-Descriptive@rt.cpan.org> [2010-05-14T23:49:43] Show quoted text
> returns an ARRAY object, not a list of the values. > > That is, after > > @java_opt = $commandLine->java_opt(); > printf("@java_opt , last is %d, elt 0 is %s\n", $#java_opt, $java_opt[0]); > > this prints as > > ARRAY(0x109a9db0) , last is 0, elt 0 is ARRAY(0x109a9db0) > > How do I get to the elements, i.e. each of the values from the command line?
It's just a reference to an array. Consider consulting "perlreftut" my $java_opt = $commandLine->java_opt; for (0 .. $#$java_opt) { print "java_opt element $_ is $java_opt->[$_]\n"; } Let me know if that doesn't help! -- rjbs
From: David.Biesack [...] sas.com
Yes, that helps. I added an annotation on http://www.annocpan.org/~RJBS/Getopt-Long-Descriptive- 0.085/lib/Getopt/Long/Descriptive.pm to clarify this.
By the way, your comment about doing $opt->{$foo} is not a great idea. It can lead to typos propagating into uncaught errors. You could just say: $opt->$foo instead. -- rjbs
From: David.Biesack [...] sas.com
On Mon May 17 09:06:15 2010, RJBS wrote: Show quoted text
> By the way, your comment about doing $opt->{$foo} is not a great idea. > It can lead to typos > propagating into uncaught errors. You could just say: $opt->$foo > instead.
In general, I agree. However, sometimes it is necessary. For example, I'm combining Getopt::Long::Descriptive with Config::General so that user's can specify options from the command line or a config file, so I need one function that will let me easily load options by name from either place - in such a case, it is convenient to pass the option name to a common function that checks the command line for the option, then if it is not there, falls back on the config file, or a default. It's much easier to pass just the option name as a parameter and be able to do $opt- Show quoted text
>{$optionName}