在 Perl 中使用未初始化的值替换 (s///) 错误 [英] Use of uninitialized value in substitution (s///) error in Perl
本文介绍了在 Perl 中使用未初始化的值替换 (s///) 错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我不习惯 Perl,但不得不创建这个函数.
I'm not used to Perl but had to create this function.
sub getPrice {
my $url = shift;
my $prdid = shift;
my $count = shift;
my $totcount = shift;
print "($count/$totcount) Fetching Product Price : $prdid .";
my $rs = sendRequest('GET', $url);
print "url :".$url;
print "..\n";
$rs =~ s!.*Unit Price Excl. VAT!!s;
$rs =~ s!</table>.*!!s;
$rs =~ m!([0-9,]+) +EUR!;
$rs = $1;
$rs =~ s/,/./;
return $rs;
}
当我调用这个函数时,我得到这个错误.
When I call this function I get this error.
Use of uninitialized value in substitution (s///)
错误指出了$rs =~ s/,/./;
行.
我更换它的方式有什么错误吗??
Is there any error in the way I'm replacing it??
$url 值有效.
推荐答案
如果 $rs 未定义,那么一定是因为匹配 "$rs =~ m!([0-9,]+) +EUR!;
" 失败,$1
未定义.添加一些战略性印刷声明应该会有所帮助.
If $rs is undefined, then it must be because the match "$rs =~ m!([0-9,]+) +EUR!;
" failed, leaving $1
undefined. Adding some strategic print statements should help.
这篇关于在 Perl 中使用未初始化的值替换 (s///) 错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文