How can I get a call stack listing in Perl?

后端 未结 8 703
慢半拍i
慢半拍i 2020-12-02 08:59

Is there a way I can access (for printout) a list of sub + module to arbitrary depth of sub-calls preceding a current position in a Perl script?

I need to make chan

8条回答
  •  既然无缘
    2020-12-02 09:28

    This code works without any additional modules. Just include it where needed.

    my $i = 1;
    print STDERR "Stack Trace:\n";
    while ( (my @call_details = (caller($i++))) ){
        print STDERR $call_details[1].":".$call_details[2]." in function ".$call_details[3]."\n";
    }
    

提交回复
热议问题