Perl (Scripting) - File::Basename module

by
Jeremy Canfield |
Updated: October 19 2020
| Perl (Scripting) articles
In this example, the $file variable contains the absolute path to example.txt.
my $file = "/tmp/example.txt";
Printing the $file variable . . .
print "$file \n";
. . . will return the absolute path to example.txt.
/tmp/example.txt
The File::Basename module can be used to create parse the filename and base directory. In this example, the $base_directory variable will contain a value of "/tmp" and the $file_name variable will contain a value of "example.txt".
my $base_directory = File::Basename::dirname($file);
my $file_name = File::Basename::basename($file);
Did you find this article helpful?
If so, consider buying me a coffee over at