in reply to Troubleshooting perl runtime errors

I'm going to bite on BrowserUK's post, and add a bit to it. Here, still using his technique, we create a hash reference with the variables we want to log if the warning contains uninitialized, and dump them all with their names and values to the log file.

Since this appears to be happening only in one spot in your script, doing it this way is trivial. It's quite a bit more complex if you are seeing these things in numerous spots in a 1194+ line script.

use warnings; use strict; use Data::Dumper; open my $log_fh, '>', 'log.txt' or die $!; my @HR = (1, 2, undef, 3); my $thing = undef; my $blah = 99; { local $SIG{__WARN__} = sub { if ($_[0] =~ /uninitialized/){ my $warn = { '@HR' => \@HR, '$thing' => $thing, '$blah' => $blah, }; print $log_fh Dumper $warn; print $log_fh "\n"; } }; my $x = sprintf $thing, @HR; }

...and this is what is logged:

$VAR1 = { '$blah' => 99, '$thing' => undef, '@HR' => [ 1, 2, undef, 3 ] };
update: typo fixes, removed eval. /update