getopts() from Getopt::Std
Posted on 1998-11-04
I am using getopts() in a perl program. The synopsis is like this:
program.pl [-r] -d [DD/MM/YY]
Now, typically $opt_d would get the date mentioned as DD/MM/YY. But I want a default action to take place if it is left out. So really it is optional. If DD/MM/YY is omitted, then today's date will be used.
The problem using getopts(rd:) is that it will complain that the date is empty because it feels that $opt_d must have an argument (or be defined?). And the problem using getopts(rd) is that $opt_d will always be 1 if used with the '-d' flag because it is Boolean. It never gets the actual string following the '-d' flag. How can I take care of this without reverting to @ARGV ?