我正在测试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: something's wrong
,$body->param->{aa}
不是STRING?如何使它成为一个STRING?
答案 0 :(得分:6)
something's wrong
是warn
函数在收到空字符串或没有输入时输出的默认消息。
$ 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"