Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re: Perl debug. How do I find calling line number?

by strat (Canon)
on Sep 26, 2004 at 10:45 UTC ( #393918=note: print w/ replies, xml ) Need Help??


in reply to Perl debug. How do I find calling line number?

For development- or debugging-purpose I like to use something like the following piece of code:

# somewhere at the beginning of the code $SIG{__WARN__} = \&Warning; $SIG{__DIE__} = \&Die; # anywhere # ------------------------------------------------------------ sub Warning { my @text = @_; warn "------------------------------------------------------------ +\n"; warn "WARNING: @text\n"; my $count = 0; { my ($package, $filename, $line, $sub) = caller($count); last unless defined $line; warn sprintf("%02i %5i %-35s %-20s\n", $count++, $line, $sub, $filename); redo; } } # Warning # ------------------------------------------------------------ sub Die { my @text = @_; warn "------------------------------------------------------------ +\n"; warn "FATAL ERROR: @text\n"; my $count = 0; { my ($package, $filename, $line, $sub) = caller($count); last unless defined $line; warn sprintf("%02i %5i %-35s %-20s\n", $count++, $line, $sub, $filename); redo; } exit 1; } # Die # ------------------------------------------------------------

This installs "signal handlers" for die and warn which are executed every time when the functions die and warn are executed and print a backtrace on how the line the warning or die was produced was reached...

Best regards,
perl -e "s>>*F>e=>y)\*martinF)stronat)=>print,print v8.8.8.32.11.32"


Comment on Re: Perl debug. How do I find calling line number?
Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://393918]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (4)
As of 2014-10-25 05:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    For retirement, I am banking on:










    Results (142 votes), past polls