如何在Perl中只打印调用函数



我正在尝试在Perl中打印调用函数。它按照期望显示。

代码如下:

#!/usr/bin/perl
use strict; use warnings;
my $a = 5;
my $b = fun1($a);
print "a:$a ** b:$bn";
sub fun1 {
my $r = shift;
my $s = fun2($r);
return $s;
}
sub fun2 {
my $p = shift;
print "the calling function is:", (caller 1)[3], "n";
print "and you're in:", (caller 0)[3], "n";
my $q = $p * 5;
return $q;
}

输出:

the calling function is:main::fun1
and you're in:main::fun2
a:5 ** b:25

如何只打印fun1fun2,而不是分别打印main::fun1main::fun2

如果有一种方法可以按照我上面所说的打印它们,那就太好了。否则我将不得不修改结果:(

您可以使用以下命令:

my $name = $full_name =~ s/^.*:://sr;

最新更新