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

Getopt::Lazy does not print usage message or anything else

我需要一些使用 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.

我做错了什么?

该模块的 SYNOPSIS 与实际代码完全不一致。代码中没有调用 getoptusage 的函数。它们实际上被称为 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;

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