2015-04-12 63 views
3

我需要知道从哪个perl文件调用了我的函数。比方说,我有一个具有以下功能如下模块(MyModule.pm):如何知道从哪个perl模块或文件调用该函数

package MyModule; 

sub myFunc{ 
    # Here I need to print the name of the file that the function was called from 
} 

和脚本myScript.pl使用MyModule并调用函数myFunc()

use MyModule; 
MyModule->myFunc(); 

我在这里需要调用myFunc()到打印“myScript.pl

有什么办法可以在Perl中做到这一点?

回答

6

里面方法,

sub myFunc{ 
    my ($package, $filename, $line) = caller; 
    print $filename; 
} 

检查perldoc -f caller了解更多详情。

相关问题