【发布时间】:2015-10-09 12:37:16
【问题描述】:
我在使用 perls Getopt::Lazy 模块时需要一些帮助。我尝试了 cpan 页面中的示例:
#!/usr/bin/perl
#
#use warnings;
#use strict;
use Getopt::Lazy
'help|h' => 'Show this help screen',
'verbose|v' => 'Show verbose output',
'output|o=s' => ["[FILE] Send the output to FILE", 'getopt.out'],
'output-encoding=s' => ['[ENCODING] Specify the output encoding', 'utf8'],
-summary => 'a simple example usage of Getopt::Lazy',
-usage => '%c %o file1 [file2 ..]',
;
getopt;
print usage and exit 1 unless @ARGV;
当我将它放入一个文件并像 ./mygetopt.pl -h 一样执行它时,我希望打印帮助消息,但没有任何反应。当我在没有 -h 参数的情况下调用它时,我希望它会打印使用消息。不会发生这样的事情。此外,当我使用严格和警告时,我会收到类似
Unquoted string "usage" may clash with future reserved word at ./mygetopt.pl line 14.
Bareword "getopt" not allowed while "strict subs" in use at ./mygetopt.pl line 13.
Execution of ./mygetopt.pl aborted due to compilation errors.
我做错了什么?
【问题讨论】:
-
Getopt::Long + Pod::Usage 示例stackoverflow.com/questions/22104215/…
-
更新的、更容易阅读的例子:gist.github.com/sirhc/621139
-
看起来 RT 票成功了。 CPAN 上的新版本,带有固定的概要。
标签: perl getopt-long