Error: Daemon Perl Use of uninitialized value $bellsTotal in concatenation (.) or string at /var/lib/tool/returnsmh.pl line 374
Resultuse 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.*
Code:
$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));
Where: $emailBody .= "Total campanas procesados: ".$campanasTotal."\n";
It would be the affected line
The warning is because you didn't assign a value to that variable, and you're trying to get that value.
Possibles scenarios:
Many times it happens because of a typo when using the variable. For example, it was
$totalCampanas
and was used$campanasTotal
in some line.Or when declared, but not assigned a value:
Other times, it is because they are defined within some control structure, but it does not end up executing. For example, this code would give the same error:
As a result of an assignment, a variable could be left as
undef
. For example:It is important to clarify that it is not an error, but a warning. The script will continue to run.
It is usually recommended to add at the beginning of your script:
to be able to identify errors before they are generated when executing.