第一种,看上去蛮简洁的
use Getopt::Long;
my $getopt = new Getopt::Long::Parser;
$getopt->configure("bundling", "no_ignore_case");
$getopt->getoptions($options,
'server|S=s',
'help|h',
) or exit WRONG_USAGE;
if($options->{'help'}) {
&help;
}
第二种,忘记哪抄来的了,看上去很累赘
GetOptions
("l|logfile=s" => \$log_file,
"h|help" => \$help);
!($help) || print_help ();
附送个ruby的getopt
require 'getoptlong'
opts = GetoptLong.new(
['--action','-C',GetoptLong::REQUIRED_ARGUMENT],
['--hostName','-H',GetoptLong::OPTIONAL_ARGUMENT],
['--help','-h',GetoptLong::NO_ARGUMENT]
)
opts.each do |opt,arg|
case opt
when '--action'
action = arg
when '--hostName'
hostName = arg
when '--help'
help
end
end
阅读(1159) | 评论(0) | 转发(0) |