gpt4 book ai didi

perl - 警告 : something's wrong when ref $body->param->{aa}

转载 作者:行者123 更新时间:2023-12-02 08:14:59 25 4
gpt4 key购买 nike

我正在测试 HTTP::Body,

然后

my $body = HTTP::Body->new($ct, $cl);
#..
use Data::Dumper;
warn Dumper($body); #A
warn ref $body; #B
warn Dumper($body->param); #C
warn ref $body->param; #D
warn Dumper($body->param->{aa}); #E
warn ref $body->param->{aa}; #F

输出:

#A
$VAR1 = bless( {
'param_order' => [
'aa',
'bb'
],
'param' => {
'aa' => 'b',
'bb' => 'a',
},
'cleanup' => 1
}, 'HTTP::Body::MultiPart' );
#B
HTTP::Body::MultiPart at
#C
$VAR1 = {
'aa' => 'b',
'bb' => 'a',
};
#D
HASH at
#E
$VAR1 = 'b';
#F
Warning: something's wrong at

为什么 Warning: somethings wrong, $body->param->{aa} 不是 STRING?如何使其成为字符串?

最佳答案

something's wrongwarn 函数在接收到空字符串或没有输入时输出的默认消息。

$ perl -e warn
Warning: something's wrong at -e line 1.

$ perl -e 'warn ""'
Warning: something's wrong at -e line 1.

$ perl -e '$body={param=>{aa=>"b"}};warn ref($body->{param}{aa})'
Warning: something's wrong at -e line 1.

我想您也对 ref 对普通标量(例如字符串)的作用感到困惑。如果 ref 的输入不是引用,则输出为空字符串。

print ref(42);                 # no output
print ref(undef); # no output
$foo="abc"; print ref($foo); # no output
warn ref($foo); # like warn "", so "something's wrong"

关于perl - 警告 : something's wrong when ref $body->param->{aa},我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42847822/

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