Bootstrap FreeKB - Perl (Scripting) - scriptname $0
Perl (Scripting) - scriptname $0

Updated:   |  Perl (Scripting) articles

The $0 variable can be used to get the name of the Perl script being invoked. For example, let's say you have a Perl script named foo.pl. Here is how you would show that foo.pl is the name of the script.

#!/usr/bin/perl
use strict;
use warnings;
print "Script name = $0 \n";

 

Or, more commonly, scriptname is stored in a constant variable.

#!/usr/bin/perl
use strict;
use warnings;
my $scriptname = $0;
print "Script name = $scriptname \n";

 

Which should return the following.

Script name = foo.pl

 




Did you find this article helpful?

If so, consider buying me a coffee over at Buy Me A Coffee



Comments


Add a Comment


Please enter 4540da in the box below so that we can be sure you are a human.