Search your unanswered perl queries
Google

Thursday, October 30, 2008

Getopt::Long :s option specifier

: s option of getopt::long come very much handy when one is looking for the following requirement

1) If a command line option is passed a paramter it is taken as a value for the given option

i.e perl program -option1 value1

$option1 will take value1.

2) If a command line option is not mentioned then variable remains undefined.

i.e perl program

$option1 will remain undef.

3) If a command line option is mentioned but paramter is not passed, then a empty string will be assigned to $option if :s is used and 0 if :i is used

i.e perl program -option1

$option will be q{}... an empty string.

Please take a look at http://search.cpan.org/dist/Getopt-Long/lib/Getopt/Long.pm for further information.

No comments: