I need to know from which perl file my function was called. Let's say I have the following module (MyModule.pm
) which has the following function:
package MyModule;
sub myFunc{
# Here I need to print the name of the file that the function was called from
}
And the script myScript.pl
uses MyModule
and calls the function myFunc()
:
use MyModule;
MyModule->myFunc();
I need the call to myFunc()
here to print "myScript.pl
"
Is there any way to do this in Perl?
Inside method,
sub myFunc{
my ($package, $filename, $line) = caller;
print $filename;
}
Check perldoc -f caller
for more details.
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加