Use of uninitialized value in concatenation (.) or string at…

Written by James McDonald

October 15, 2009

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.


Submit a Comment

Your email address will not be published.

You May Also Like…


Zebra Printer Language The above website has a page where you can enter ZPL and it...

PHP Iterators

Just came across a Youtube talk "Iterators in PHP" by Jake Smith published in 2014 that steps through the many...

PHP array_map Multiple Arrays

array_map can take multiple arrays. I like how it starts mapping through them starting at the first element of each...