Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re: Finding what called a subroutine

by davido (Archbishop)
on Apr 05, 2013 at 23:46 UTC ( #1027231=note: print w/replies, xml ) Need Help??


in reply to Finding what called a subroutine

See Carp:

use Carp qw(croak); sub foo { croak; } foo();

Here, carp reports from the perspective of the caller. In this case, it will report both the line in the sub that died, and the line in the calling code that called the sub that died.

If you run the code above as "mytest.pl", unmodified it would output the following:

at ./mytest.pl line 4. main::foo() called at ./mytest.pl line 7

The Carp module also provides "confess" which will offer a more detailed back-trace.

If you just want to log calls you can use Carp's "carp" and "cluck" functions to get similar output to warn, but from the caller's perspective.


Dave

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1027231]
help
Chatterbox?
[mz2255]: I wish I had an online shop but sadly no. The title field definitly wasn't short, had a perl module in the title with 5-6 additional words.
[ambrus]: you can also try to just post again in case it was some intermittent error
[mz2255]: Tried again, denied. Maybe my code is just so bad the site refuses to post it.
[marto]: no, there's a bug, sometimes...
[mz2255]: ok, well thanks for looking into it. I'll try again later.

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (14)
As of 2017-10-19 15:38 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My fridge is mostly full of:

















    Results (255 votes). Check out past polls.

    Notices?