I am trying to write Perl code which is warning free, unless there is a real problem.
Some of the code I was using to create an XML file using the "XML::DOM" Perl Module was throwing a "Use of uninitialized value in concatenation (.) or string at..." warning.
The warning thrown by XML::DOM ended up being unrelated to the XML I was trying to create and was instead caused by trying to use a variable that was undefined.
One answer (there are probably many better ways to do this in Perl) to this problem is to use
$variable = "" unless defined $variable;
Another thing I tried to help clean up my code was to put the "use warnings" pragma at the top of the script. It showed me some very specific warnings which enabled me to improve my dodgy coding aswell.
0 Comments