http://qs321.pair.com?node_id=893498


in reply to Dynamic option

I'm not exactly clear what you mean by "user input" since the entire command line is "user input" - do you mean that you have an option that can be assigned an arbitrary number of values?

If so, you can do something like this on the command line:

findfiles --input=data --input=modem --input=apps -des "finding files" + -r 1000

And in your getopt definition, you would add, "input=s@" instead of "input=s". Alternatively, you could allow your users to assign a comma delimited list (no internal spaces), like this:

findfiles --input=data,modem,apps -des "finding files" -r 1000

That would add an extra processing step: just in case someone used the first syntax (multiple options), you would concatenate the options with a comma to form one long comma delimited list. Then you would split the long list back into individual options. Like this (note: pseudocode - might have typos):

my @input = split(/,/, join(',', $options{input}))

If you've learned about Getopt::Long from reading code examples, you might want to take a look at the Getopt::Long documentation. It has a fair bit of discussion about how to have multi-valued options and some examples. Multivalued command line arguments have been supported by the version that ships with Perl since at least 5.8.8