[Chicago-talk] alternatives to Getopt::Long

Mike Fragassi frag at ripco.com
Fri May 7 15:15:46 CDT 2004

On Fri, 7 May 2004, Steven Lembark wrote:
> -- Mike Fragassi <frag at ripco.com>
> > Getopt::Long doesn't seem to have the ability to take command-line
> > arguments like
> >
> >    --foo a b c --bar 1 2 3
> There is now way for it to know that "a b c" is an argument.

But why not?  You can already do

   GetOptions('foo=s' => \@foo);

It should at least be feasible to go

   GetOptions('foo=s+' => \@foo);  # or 'foo=sl', or 'foo=S', or whatever

which could tell it to keep shifting @ARGV into @foo until you hit the
next --switch.  Or a configuration parameter (like 'auto_abbrev' or
'permute') to do this for all array parameters by default.  I haven't
tried hacking Getopt::Long (yet), but I was surprised this sort of thing
isn't in place.

> No reason you cannot use some extended options for processing
> the stuff (lotsawork) or just:
>     --foo='a b c';
...which is the same as
> >    --foo a,b,c --bar 1,2,3  # and split on commas later

> You could also use:
>     --foo=a --foo=b --foo=c
...which is the same as
> >    --foo a --foo b --foo c --bar 1 --bar 2 --bar 3

I know these work; I know I can hack @ARGV directly; I was wondering if
there's a module that already does what I'm asking.  (This is all about
the First Virtue, guys.)

-- Mike F.

More information about the Chicago-talk mailing list