gpt4 book ai didi

perl - 使用 Getopt::Long Perl 时的未知选项

转载 作者:行者123 更新时间:2023-12-02 08:19:05 27 4
gpt4 key购买 nike

我有一个基本上接受如下输入的 perl 文件:

use strict;
use File::Copy;
use File::Path;
use Sys::Hostname;
use Getopt::Long;
use File::Spec;
use File::Compare;
use MIME::Base64;
use Digest::MD5 qw(md5_hex);
my %hmpParams;
my $keybindings;
my $keybindings1;
my $keybindings2;
my $filename;
my $osname;
my $copy="cp";

&parseCommandLineParams();

while ((my $k, my $v) = each %hmpParams ){
print($k . " = " . $v . "\n");
}


sub parseCommandLineParams(){
GetOptions ( 'bindings:s' => \$hmpParams{bindings},
'filename:s' => \$hmpParams{filename},
'key:s' => \$hmpParams{key},
'bindings1:s' => \$hmpParams{bindings1},
'bindings2:s' => \$hmpParams{bindings2}
);
}

我按如下方式执行这个 Perl 文件:

perl test.pl "-bindings" "+WBAOBtud/UuM7uuCG2T+0ZvoCeuu/x24ovYkwjI2YM=" "-filename" "/tmp/keyMapperFile_2016-08-24-04:43:06" "-key" "avqijvmlf5ipq_5j0038opvhqmh_28jm8d913ptv0_3ie1ctia2cdqd" "-bindings1" "" "-bindings2" ""

输出:

Unknown option: wbaobtud/uum7uucg2t+0zvoceuu/x24ovykwji2ym
bindings2 =
filename = /tmp/keyMapperFile_2016-08-24-04:43:06
bindings =
bindings1 =
key = avqijvmlf5ipq_5j0038opvhqmh_28jm8d913ptv0_3ie1ctia2cdqd

我看到只要选项的值中有一个前面的 + 号,它就不会将其识别为值,而是将其视为选项。我该如何解决这个错误?这背后的原因是什么?

最佳答案

您需要禁用 getopt_compat 选项以防止前导 + 被视为等同于 --:

getopt_compat
Allow "+" to start options. Default is enabled unless
environment variable POSIXLY_CORRECT has been set, in which
case "getopt_compat" is disabled.

如在

use Getopt::Long qw(:config no_getopt_compat);

use Getopt::Long;
Getopt::Long::Configure("no_getopt_compat");

关于perl - 使用 Getopt::Long Perl 时的未知选项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39124053/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com