Bootstrap FreeKB - Perl (Scripting) - File::Basename module
Perl (Scripting) - File::Basename module

Updated:   |  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 Buy Me A Coffee



Comments


Add a Comment


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