|We don't bite newbies here... much|
Parsing command line options without knowing what they areby DrWhy (Chaplain)
|on Nov 25, 2010 at 00:58 UTC||Need Help??|
DrWhy has asked for the
wisdom of the Perl Monks concerning the following question:
This seems like such a simple idea, but I can't seem to find any module that does it. I have a script that needs to take in a bunch of command line options in an open-ended set. I don't want to name them all in the script. So I want a GetOptions() function that has the ability to just process the command line arguments and treat the things that look like options as if they were options and not throw up all over my screen just because I didn't tell it ahead of time that this these options might be coming in. (And also not just ignore them and leave them in @ARGV.)
perl -s kind of does this, but I need it to be able to handle long options names that take values and don't require '=' between option name and value. I guess I'd like to see an addition like this for Getopt::Long::GetOptions:
where '=s' says for anything else that looks like a command line options process it as if it were and as if it required a string argument, stuffing the results as key/value pairs in %others.
Or am I just being dense and there's some really straightforward way to do this that I'm not seeing?
"If God had meant for us to think for ourselves he would have given us brains. Oh, wait..."