On Wed Mar 14 03:24:13 2012, JV wrote:
Show quoted text> On Tue Mar 13 19:52:03 2012, SHARYANTO wrote:
> > I wonder if Getopt::Long can support non-alphanumeric characters
aside
Show quoted text> > from "-". For example:
> >
> > --foo:json
> > --foo:yaml
> > --name.min
> > --name.max
>
> It could but it goes against all existing conventions for command line
> options.
>
> Also, it is easy to introduce ambiguities, e.g.
>
> GetOptions( "foo:s" )
>
> Does this mean the option name is "foo:s" or is it option "foo" taking
> an optional string argument?
>
> So I'd suggest to reconsider whether this would be really necessary.
> Is there a reason "--name-min" and such cannot be used in your case?
Background:
One of my modules translates command-line options to function
arguments, e.g. --foo 1 to $foo = 1 and --bar-baz 2 or --bar_baz 2 to
$bar_baz = 2. Although only alphanums + underscores are allowed for the
argument names, all kinds of names should be possible.
I also want to allow YAML (or JSON) decoding so the module can assign
data structures to the arguments, e.g. --foo.json='[1,2]'.
There is also another module which I'm working on, which translates
command-line options to data access query (like SQL). The options are
table column names, and I want to allow filters for them, like --
col.min=1 --col.max=10 which will eventually be translated into SQL
clause 'col BETWEEN 1 AND 10'. Or even --col.not.yaml='{a: 1}' which
can be translated into Perl expression 'Dump($col) ne Dump({a=>1})'.
Of course I can also use --foo-json, --col-min, --col-max, --col-not-
yaml, but an out-of-band separator character is preferred. As one can
imagine an argument or column named being named $foo_json or 'col_min'
and there can be confusion on the command-line.
As for option specification syntax, we can do something like:
GetOptions( "[foo:yaml]:s" )
GetOptions( "[col.min]:i" )
GetOptions( "[another=opt+]=s" )
although I'm not sure you want to go there.
I believe some characters like dot (.) and slash (/) currently do not
clash with characters used in option specification.
Regards,
Steven