If you cannot use (or would like to avoid) non-core modules, here is a simple routine that I came up with:
#!/usr/bin/perl use strict; use warnings; sub printstack { my ($package, $filename, $line, $subroutine, $hasargs, $wantarray, $evaltext, $is_require, $hints, $bitmask, $hinthash); my $i = 1; my @r; while (@r = caller($i)) { ($package, $filename, $line, $subroutine, $hasargs, $wantarray, $evaltext, $is_require, $hints, $bitmask, $hinthash) = @r; print "$filename:$line $subroutine\n"; $i++; } } sub i { printstack(); } sub h { i; } sub g { h; } g;
It produces a conclusion as follows:
/root/_/1.pl:21 main::i /root/_/1.pl:25 main::h /root/_/1.pl:28 main::g
Or insert:
for (my $i = 0; my @r = caller($i); $i++) { print "$r[1]:$r[2] $r[3]\n"; }
You can find the documentation for the subscriber here .
x-yuri Jun 14 '19 at 10:48 2019-06-14 10:48
source share