Perl script: Auto Detect the script file name

CODE:

[code language=”perl”]
use File::Basename;
my $progname = basename($0);
$progname =~ m/(.*)(\.)(.*)/;
print "Script name along with extension: [$progname]\n";
print "Script name without extension: [$1]\n";

[/code]

OUTPUT:

[code language=”perl”]
C:\>perl get-script-name.pl
Script name along with extension: [get-script-name.pl]
Script name without extension: [get-script-name]
C:\>
[/code]

Leave a Reply

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