getopts::long & option string argument

  • Thread starter Florian Kaufmann
  • Start date
F

Florian Kaufmann

What can Getopt::Long, or any other 'standard' module offer me for
this problem task:

I have an option which expects a string argument. But a) only a finite
set of strings are to be accepted b) unique abbreviations shall be
accepted, e.g. if the set of valid strings is ("foo","bar","fly") then
"fo" should stand for "foo".

An example for such a use case is the --backup[=CONTROL] option of
many coreutils tools as for example cp, ln, install. CONTROL can only
be ("no","off","numbered"... and a few more).
 
J

James Spahlinger

Florian said:
What can Getopt::Long, or any other 'standard' module offer me for
this problem task:

I have an option which expects a string argument. But a) only a finite
set of strings are to be accepted b) unique abbreviations shall be
accepted, e.g. if the set of valid strings is ("foo","bar","fly") then
"fo" should stand for "foo".

An example for such a use case is the -- backup[=CONTROL] option of
many coreutils tools as for example cp, ln, install. CONTROL can only
be ("no","off","numbered"... and a few more).
What you want to do is exactly what Getopt is
for.
 
F

Florian Kaufmann

What you want to do is exactly what Getopt is
for.

So which part of "perldoc Getopt::Long" tells me how I accomplish
point a) and b) from my question? I already used Getopt::Long before,
so I know the basics. Reading the documentation, the 'only' limitation
upon the argument of an option I can make, is to tell wheter it has to
be a string, an integer, or a float. I cant say, it has to be a string
of a certain finite set. See section "options with values".
 
J

Jürgen Exner

[Quoting in full]
James Spahlinger said:
Florian said:
What can Getopt::Long, or any other 'standard' module offer me for
this problem task:

I have an option which expects a string argument. But a) only a finite
set of strings are to be accepted b) unique abbreviations shall be
accepted, e.g. if the set of valid strings is ("foo","bar","fly") then
"fo" should stand for "foo".

An example for such a use case is the -- backup[=CONTROL] option of
many coreutils tools as for example cp, ln, install. CONTROL can only
be ("no","off","numbered"... and a few more).
What you want to do is exactly what Getopt is
for.

What on earth did you do with the quoted text. You _REALLY_ should check
your quoting style. It is absolutely impossible to tell what you were
quoting and what you were saying.

jue
 
U

Uri Guttman

TJM> Jürgen Exner said:
[Quoting in full]
James Spahlinger said:
Florian Kaufmann wrote:

What can Getopt::Long, or any other 'standard'
module offer me for
this problem task:

I have an option which expects a string
argument. But a) only a finite
set of strings are to be accepted b) unique
abbreviations shall be
accepted, e.g. if the set of valid strings is
("foo","bar","fly") then
"fo" should stand for "foo".

An example for such a use case is the --
backup[=CONTROL] option of
many coreutils tools as for example cp, ln,
install. CONTROL can only
be ("no","off","numbered"... and a few more).
What you want to do is exactly what Getopt is
for.

What on earth did you do with the quoted text. You _REALLY_ should check
your quoting style. It is absolutely impossible to tell what you were
quoting and what you were saying.


TJM> But it is a pretty good bellweather of the quality of the comment
TJM> offered...

beyond that, you CAN do what the OP wants with getopt::long using a
callback sub which is a closure. it would contain the hash of valid
values as well as a ref to the variable to set. see the docs for how to
use that. also Getopt::Euclid has code constraints that allow this very
thing as well and it does much more including pod and usage generation
all in one.

uri
 

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,755
Messages
2,569,537
Members
45,022
Latest member
MaybelleMa

Latest Threads

Top