无法解析命令行长选项

sco*_*art 6 perl getopt-long command-line-arguments

#!/usr/bin/perl -sw
use strict;
use warnings;
use Getopt::Long;

my $remote = 0;
my $test = 0;
GetOptions ('remote' => \$remote, 'test' => \$test);
print "$remote:$test\n";
Run Code Online (Sandbox Code Playgroud)

perl test.pl --remote --test

以上打印"0:0".我是Perl的新手,所以我无法确定为什么这不起作用.

我还运行了http://perldoc.perl.org/Getopt/Long.html#Simple-options中的"简单选项"部分,但也没有产生任何内容.

Jon*_*hop 11

我相信-s你在she-bang线上包含的命令行选项正在咬你.根据perlrun文档,-s命令行选项:

在程序名之后但在任何文件名参数之前(或在 - 的参数之前),允许对命令行上的开关进行基本的开关解析.

如果删除该选项,事情应该按预期工作.我还建议删除,-w因为你已经在使用该use warnings指令(该use warnings指令功能更全面,基本上替换了该-w选项).

所以,长话短说,让你的第一线:

#!/usr/bin/perl
Run Code Online (Sandbox Code Playgroud)