是Perl的GetOpt :: Long接受交换机的缩写是一个错误吗?
发布时间:2020-12-15 23:31:17 所属栏目:大数据 来源:网络整理
导读:这是我编写的用于测试命令行参数处理的简单脚本: use Getopt::Long;my $help = 0;GetOptions('help|h|?' = $help,) or die "Error!";print "OKn"; 我得到的结果如下: D:perl test.pl --helpOKD:perl test.pl --hellUnknown option: hellError! at test
这是我编写的用于测试命令行参数处理的简单脚本:
use Getopt::Long; my $help = 0; GetOptions( 'help|h|?' => $help,) or die "Error!"; print "OKn"; 我得到的结果如下: 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 有没有人注意过这个?行为(接受他和hel而不是帮助)是一个潜在的错误吗? 解决方法
不,这是故意的.它接受选项的最短非模糊版本,所以如果你有另一个选项“–hex”,它将不接受“–he”但它会接受“–hel”.
(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |