http://www.perlmonks.org?node_id=933686

alain_desilets has asked for the wisdom of the Perl Monks concerning the following question:

Hi folks,

I have been using 'use strict' for years, but was only recently introduced to 'use warnings'. While I find it generally useful, it tends to generate warnings in contexts where I think it shouldn't, in particular when trying to print a variable whose value is undef.

For example, consider the following code:

use strict; use warnings; my @some_array = (1, 2, undef, 4, 5); for (my $ii=0; $ii < scalar(@some_array); $ii++) { print "Value at position $ii: $some_array[$ii]\n"; }

This code prints the elements of an array, some of which have value undef. If you run it, you get error messages

"Use of uninitialized value $some_array2 in concatenation (.) or string at etc..."

Yet, it's perfectly fine for an array to contain some values of undef. Why shouldn't I be allowed to print them?

Is there a way around this issue? Thx.