FindBin - Get the path to the directory where the script resides
You can use the FindBin module to get the path of the directory where the script resides.
# Load module use FindBin;
The path to the directory where the script resides is assigned to the $FindBin::Bin a package variable.
# Get the path of the directory where the script resides my $script_dir = $FindBin::Bin;
FindBin is a slightly unusual module, but it's the standard way to get the path to the directory where the script resides.
Set the module loading path
The FindBin module is used together with lib module and often sets the module loading path.
By doing the following, you can set the directory called lib in the directory where the script exists as the loading path of the module.
# Add the lib directory of the directory where the script exists to the search path use FindBin; use lib "$FindBin::Bin/lib";
Script base name
You can get the base name of the script with $FindBin::Script .
use FindBin; $FindBin::Script