I have a script
#!/usr/bin/env perl
use strict;
use warnings FATAL => 'all';
use feature 'say';
use autodie ':default';
use mwe 'tmp';
tmp();
that calls a Perl module 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;
but when I run this script, the filename appears from the module:
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
I'm still new at writing modules, so criticism there is appreciated, if my minimal working example isn't well-written.
My question:
I'm aware that I could pass the file /home/con/Scripts/mwe.pl
as a parameter to the subroutine tmp
, but is there a way that I could get a subroutine like tmp
to return the script filename instead automatically?