in reply to Re: Re: GetOpt::Long usage style
in thread GetOpt::Long usage style
I know this is ancient, but since it's high on the Google hit list, I wanted to mention one thing...
This very cool trick does not work for @arrays. :-(
This:
does *NOT* DWIM. According to "perlref":use Getopt::Long; GetOptions( 'single=s' => \(my $single = ''), 'multi=s' => \(my @multi = ()), );
As a special case, "\(@foo)" returns a list of references to the contents of @foo, not a reference to @foo itself.I tried all kinds of permutations, and the best I could come up with was:
which, isn't quite as clean, IMHO.use Getopt::Long; GetOptions( 'single=s' => \(my $single = ''), 'multi=s' => do { use vars '@multi'; \@multi }, );
(It *DOES*, however, keep the variable declarations and command-line options on the same line, at least, so you don't have to make changes in multiple places when adding new options. *shrug*)
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^4: GetOpt::Long usage style (\my @a)
by tye (Sage) on May 09, 2014 at 00:37 UTC | |
Re^4: GetOpt::Long usage style
by demerphq (Chancellor) on Apr 11, 2016 at 17:22 UTC |