我编写了以下代码:
my $version = sub {
print "$PROGNAME $VERSION - $AUTHOR\n";
exit 0;
};
my $usage = sub {
print "Usage: proll <options>\n";
print "Available options:\n";
print " -h, --help Print this help and exit.\n";
print " --version Print version.\n";
print " XdY Launch X dice with Y faces.\n";
exit 0;
};
my $ret = GetOptions ( "version" => \$version,
"h|help" => \$usage );
但是,如果我调用脚本--version
或--help
它不调用子例程。我哪里错了?
如果我按如下方式更改代码,它总是调用第一个子程序,也没有任何命令行参数:
my $ret = GetOptions ( "version" => &$version,
"h|help" => &$usage );