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