Perl Show Current Script Name

If you ever needed to show the currently running Perl script name, here are the examples you need.  I personally like using the following to name log files based on the script name by replacing the extension:

use File::Basename;
#Display Current Script Name
my $scriptName = basename($0);
print $scriptName
#Display Current Script Name with Different Extension - Usefull for Naming Log Files
print basename($scriptName, ".pl") . ".txt";

 

Leave a Reply

Your email address will not be published. Required fields are marked *