Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

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

by strat (Canon)
on Sep 26, 2004 at 10:45 UTC ( [id://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"

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others examining the Monastery: (6)
As of 2024-03-28 15:08 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found