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

In reply to Re: Troubleshooting perl runtime errors by stevieb
in thread Troubleshooting perl runtime errors by lvirden

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.