|Welcome to the Monastery|
Force Getopt::Long to Require ONLY Equals Sign Between Option Name and Valueby roho (Canon)
|on Oct 18, 2019 at 20:36 UTC||Need Help??|
roho has asked for the wisdom of the Perl Monks concerning the following question:
Here is what I am trying to do. I have a command line option that is defined in Getopt::Long as having an optional string value as follows:
The problem occurs when -ot (without a value) is followed by either another option or a program argument. The -ot option will take the next word as its value.
I know I can signal the end of options by using -- on the command line, but for backward compatibility before this program used Getopt::Long (the program previously used "/usr/bin/perl -s" to process command line options), I would like to tell Getopt::Long to always require an equals sign before a value so that -ot (without a value) can be followed by a program argument without the invervening -- in the command line.
Here is what I am aiming for:
This works fine. Variable $ot='123'
I need $ot to be set to the empty string '' instead of 'arg1', without the need of an intervening -- on the command line (hence the need to force Getopt::Long to require an equals sign between the option name and its value).
Again, my goal is backward compatibility with the way this program was called before adding Getopt::Long, because this program is very central to the system and is literally called in thousands of places. TIA for any suggestions.
"It's not how hard you work, it's how much you get done."