Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??
Hi, there is no simple way to do that and the exact behavior as described I can't emulate (today). I believe, that it's possible with deeper knowledge in perlXS, to access the exact codeline which throw the warning and extract their content. But you can define a signalhandler and use PadWalker to print out the lexical and global variables. The following example output these warnings:
Warning: Use of uninitialized value in concatenation (.) or string at mpu.cgi line 25.
Possible variables are:
          '$GLOBAL_VARIABLE' => \'global',
          '$t' => \undef,
          '$s' => \'regular output'
#!/usr/bin/perl use strict; use warnings; use PadWalker(); use Data::Dumper(); local $SIG{'__WARN__'} = sub { if($_[0] !~ /^Use of uninitialized value/) { print @_; } else { # If there are objects, the output can be VERY large when you +increase this local $Data::Dumper::Maxdepth = 2; # takes all lexical variables from caller-nemaspace my $possibles = Data::Dumper::Dumper({ %{PadWalker::peek_my(1) +}, %{PadWalker::peek_our(1)} }); $possibles ne "\$VAR1 = {};\n" ? ($possibles =~ s/^.*?\n(.*)\n +.*?\n$/$1/ms) : ($possibles = ''); print STDERR "Warning: " . join(', ', @_) . "Possible variable +s are:\n$possibles\n"; } }; our $GLOBAL_VARIABLE = 'global'; sub mySub { my $t = undef; my $s = "regular output"; print " $s $t "; } mySub();
Warnings abouot uninitialized values are resolved, all others behave like before. This you should use only to develop. Some warings about uninitialized variables can be very large, when the caller-namespace contain many variables. Tobiwan

In reply to Re: Debugging "Use of uninitialized value" warnings. by Tobiwan
in thread Debugging "Use of uninitialized value" warnings. by cwry

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!
  • 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, 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, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • Outside of code tags, you may need to use entities for some characters:
            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.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others wandering the Monastery: (9)
    As of 2014-11-20 21:53 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      My preferred Perl binaries come from:














      Results (102 votes), past polls