这是我编写的用于测试命令行参数处理的简单脚本:
use Getopt::Long;
my $help = 0;
GetOptions(
'help|h|?' => \$help,
) or die "Error!";
print "OK\n";
Run Code Online (Sandbox Code Playgroud)
我得到的结果如下:
D:\>perl test.pl --help
OK
D:\>perl test.pl --hell
Unknown option: hell
Error! at test.pl line 10.
D:\>perl test.pl --he
OK
D:\>perl test.pl --hel
OK
Run Code Online (Sandbox Code Playgroud)
有没有人注意过这个?行为(接受他和hel而不是帮助)是一个潜在的错误吗?