這是一個簡單的腳本,我寫來測試命令行參數處理:Perl的GetOpt :: Long是否接受切換錯誤的縮寫?
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
有沒有人之前注意到這一點?行爲(接受他而不是幫助)潛在的錯誤?
謝謝。這很快。 – Andy 2009-05-28 14:29:59
您應該將答案標記爲'接受'。 – 2009-05-28 16:41:50