这是我为测试命令行参数处理而编写的一个简单脚本:
use Getopt::Long;
my $help = 0;
GetOptions(
'help|h|?' => \$help,
) or die "Error!";
print "OK\n";
我得到的结果如下:
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
有没有人注意到这一点?这种行为(接受他和他而不是帮助)是一个潜在的错误吗?