【发布时间】:2021-06-02 20:38:03
【问题描述】:
我有一个脚本
#!/usr/bin/env perl
use strict;
use warnings FATAL => 'all';
use feature 'say';
use autodie ':default';
use mwe 'tmp';
tmp();
调用 Perl 模块 mwe
use feature 'say';
package mwe;
use Cwd 'getcwd';
use Exporter qw(import);
our @EXPORT = qw(tmp);
sub tmp {
say 'written by ' . getcwd() . '/' . __FILE__;
}
1;
但是当我运行这个脚本时,文件名出现在模块中:
con@V:~/Scripts$ perl mwe.pl
written by /home/con/Scripts//home/con/perl5/perlbrew/perls/perl-5.34.0/lib/5.34.0/mwe.pm
我在编写模块方面还是新手,如果我的最小工作示例写得不好,欢迎批评。
我的问题:
我知道我可以将文件/home/con/Scripts/mwe.pl 作为参数传递给子程序tmp,但是有没有办法让我像tmp 这样的子程序自动返回脚本文件名?
【问题讨论】:
标签: perl