Perl-Sensitive Sunglasses | |
PerlMonks |
Getopt::Long to define or not to define?by jordanh (Chaplain) |
on Mar 04, 2005 at 19:30 UTC ( [id://436715]=perlquestion: print w/replies, xml ) | Need Help?? |
jordanh has asked for the wisdom of the Perl Monks concerning the following question:
I use Getopt::Long.
In the docs it gives all the examples in the form: Where the option variables are initialized to '' (or some other default). I typically declare the option variables, but don't give them an initial value, depending on the fact that they are undefined to flag to me that the option is unspecified (as opposed to set to a false value). I think this mode of operation is supported, but I'm wondering if there isn't a pitfall or practice that I'm not thinking of here. Actually, I think there's a clear implication that this mode is supported in the docs where it says: The call to GetOptions() parses the command line arguments that are present in @ARGV and sets the option variable to the value 1 if the option did occur on the command line. Otherwise, the option variable is not touched. Setting the option value to true is often called enabling the option. My way of working with it seems natural to me, but the examples and other people's code often seems to follow the other style. I recognized the pitfall that an undefined value tests false and that I need to explicitly test for defined. Is there anything else I'm missing?
Back to
Seekers of Perl Wisdom
|
|