perlmaven.com
perlmaven.com copied to clipboard
is this an unnecessary warning from Perl's undef
https://perlmaven.com/use-of-uninitialized-value
In this use case, $x becomes undef. I doubt it matters why, but as an example, reading an expected numerical value from an external database can cause it if the code return is empty.
Then a choice has to be made : create another database with not-null values, or assign a value of '0' (zero) in Perl, thus :
< if ($x[$k] eq '') {$x[$k] = 0}>
where $k is a variable that sets an index to the array @x.
When the code is run, a warning is returned for each undefined value. This isn't necessarily a problem, as the warnings can be ignored, but I would prefer to be able to set a flag to temporarily prevent the warning message being thrown.
either check if defined $x[$k]
and handle that case or you can turn off warnings that will impact till the end of the lexical scope.
See this new article: https://perlmaven.com/selectively-ignore-warnings