in reply to Getopt::Std and simple options
You might want to use getopts() instead of getopt() as the latter requires the swtich to have an arg (i.e. you need to use it as scriptname -v somearg) getopts() provides this by : to the end of switch.
Also you should check for return value from getopt/s(). If you had checked for the return value you would have seen broken usage with your code as is i.e. getopt()
use strict; use Getopt::Std; our $opt_v; # print join(':',@ARGV), "\n"; my $ret = getopts('v'); die "broken usage\n" unless $ret; print "V = ", $opt_v,$/ if defined $opt_v; __END__ V = 1
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Getopt::Std and simple options
by Dizzley (Novice) on Sep 06, 2005 at 05:39 UTC | |
by graff (Chancellor) on Sep 07, 2005 at 02:17 UTC |