How to get the name of Perl script that is running
The name of the running program can be found in the $0
variable:
print $0;
man perlvar for other special variables.
use File::Basename;
my $name = basename($0);
PS. getcwd()
and friends don't give you the script's directory! They give you the working directory. If the script is in your PATH and you just call it by name, not by its full path, then getcwd()
won't do what you say. You want dirname($0)
(dirname also is in File::Basename
).