您如何使用Getopt::Long识别未知选项?我尝试了'',但是没有按预期工作。.考虑:use Modern::Perl;use Getopt::Long;my $help='';GetOptions ('help' => \$help,'<>' => \&usage);usage() if $help;usage() if @ARGV != 1;my $fn=pop;say "FileName: $fn";sub usage { say "Unknown option: @_" if ( @_ ); say "Usage: $0 <filename>"; say " $0 --help"; say ""; exit}我只想在存在无法识别的选项时打印Unknown option(在这种情况下,是--help以外的任何其他选项)。但是现在它认为文件名是无法识别的选项。 (adsbygoogle = window.adsbygoogle || []).push({}); 最佳答案 如果usage失败,请调用GetOptions函数。 Getopt::Long将为您(到STDERR)打印Unknown option:use Modern::Perl;use Getopt::Long;my $help='';GetOptions ('help' => \$help) or usage();usage() if $help;usage() if @ARGV != 1;my $fn=pop;say "FileName: $fn";sub usage { say "Usage: $0 <filename>"; say " $0 --help"; say ""; exit}关于perl - perl Getopt::Long中的未知选项,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/22644520/ (adsbygoogle = window.adsbygoogle || []).push({});
10-09 08:58