错误: 守护进程 Perl 在 /var/lib/tool/returnsmh.pl 第 374 行的连接 (.) 或字符串中使用未初始化的值 $bellsTotal
结果use diagnostics;
*Use of uninitialized value $campanasTotal in concatenation (.) or string at
/var/lib/tool/devueltosmh.pl line 374 (#1)
(W uninitialized) An undefined value was used as if it were already
defined. It was interpreted as a "" or a 0, but maybe it was a mistake.
To suppress this warning assign a defined value to your variables.
To help you figure out what was undefined, perl will try to tell you the
name of the variable (if any) that was undefined. In some cases it cannot
do this, so it also tells you what operation you used the undefined value
in. Note, however, that perl optimizes your program and the operation
displayed in the warning may not necessarily appear literally in your
program. For example, "that $foo" is usually optimized into "that "
. $foo, and the warning will refer to the concatenation (.) operator,
even though there is no . in your program.*
代码:
$emailBody = "El proceso finalizo con exito\n\n";
$emailBody .= "================================\n";
$emailBody .= "Total devueltos procesados: ".$devueltosTotal."\n";
$emailBody .= "\n";
$emailBody .= "Total campanas procesados: ".$campanasTotal."\n";
$emailBody .= "================================\n";
$emailBody .= "Hora Inicio: ".$startDate."\n";
$emailBody .= "Hora Final: ".$endDate."\n";
$emailBody .= "================================\n\n";
$emailBody .= "Administrador\n";
$emailMensaje = encode('utf8', decode('iso-8859-1', $emailBody));
其中: $emailBody .= "Total campanas procesados: ".$campanasTotal."\n";
这将是受影响的线路
警告是因为您没有为该变量分配值,并且您正在尝试获取该值。
可能的场景:
很多时候发生这种情况是因为使用变量时的拼写错误。例如,它曾经
$totalCampanas
并且被用于$campanasTotal
某些行。或者在声明但未赋值时:
其他时候,这是因为它们是在某个控制结构中定义的,但最终没有执行。例如,此代码将给出相同的错误:
作为赋值的结果,变量可以保留为
undef
. 例如:重要的是要澄清这不是错误,而是警告。该脚本将继续运行。
通常建议在脚本的开头添加:
能够在执行时生成错误之前识别它们。