Getopt :: Lazy不打印使用消息或其他任何内容

Isa*_*aac 1 perl getopt-long

我需要一些使用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;
Run Code Online (Sandbox Code Playgroud)

当我把它放在一个文件中执行它时./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.
Run Code Online (Sandbox Code Playgroud)

我究竟做错了什么?

Dav*_*oss 6

该模块的SYNOPSIS与实际代码完全不同步.代码中没有调用函数getopt或函数usage.他们居然叫GetOptionsGetopt::Lazy::show_help(是的,一个是出口,另一种是不-谁知道为什么).重写这样的例子将起作用:

#!/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 ..]',
        ;
GetOptions;
Getopt::Lazy::show_help and exit 1 unless @ARGV;
Run Code Online (Sandbox Code Playgroud)

但考虑到文档的质量,并且鉴于该模块在七年半前显然被其作者遗弃了,我不会让它放在我的任何项目附近.建议您使用上述评论中其他人建议的解决方案之一.