Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Get first caller and its arguments

by OlegG (Monk)
on Sep 12, 2011 at 15:55 UTC ( [id://925504]=perlquestion: print w/replies, xml ) Need Help??

OlegG has asked for the wisdom of the Perl Monks concerning the following question:

Is there a way to perform subj?
sub a { b() } sub b { c() } sub c { my ($caller, $args) = get_first_caller_with_args } a("test", [1,2,3]);
Want to get
$caller = \&a, $args = ["test", [1,2,3]];

Replies are listed 'Best First'.
Re: Get first caller and its arguments
by Corion (Patriarch) on Sep 12, 2011 at 15:59 UTC

    Have you looked at caller? In what ways does it fail to do what you want?

      The main problem is that i can't get caller args with caller(). Am i wrong?
        In the caller docs, did you read this:
        Furthermore, when called from within the DB package, caller returns more detailed information: it sets the list variable @DB::args to be the arguments with which the subroutine was invoked.
        Also look (and/or use) Devel::Caller::Perl (which uses the "called within the DB package" technique) or Devel::Caller.
Re: Get first caller and its arguments
by DrHyde (Prior) on Sep 13, 2011 at 10:14 UTC
    You may find the source for Devel::StackTrace instructive.
    $ perl -MDevel::StackTrace -e ' hlagh("bar"); sub hlagh { quork("baz") } sub quork { print Devel::StackTrace->new()->as_string() } ' Trace begun at -e line 1 main::quork('baz') called at -e line 1 main::hlagh('bar') called at -e line 1

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others exploiting the Monastery: (5)
As of 2024-04-25 13:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found