Perl (Scripting) - File and Directory basename and dirname
by
Jeremy Canfield |
Updated: November 06 2023
| Perl (Scripting) articles
In this example, the $file variable contains the absolute path to example.txt.
my $file = "/home/john.doe/example.txt";
Printing the $file variable . . .
print "$file \n";
. . . will return the absolute path to example.txt.
/home/john.doe/example.txt
File::Basename can be used to parse the dirname and basename. In this example . . .
- $dirname = /home/john.doe
- $basename = example.txt
my $file = "/home/john.doe/example.txt";
my $dirname = File::Basename::dirname($file);
my $basename = File::Basename::basename($file);
Did you find this article helpful?
If so, consider buying me a coffee over at