For some reason my code is doing this wierd thing where fileparse only prints (literally) File::Basename
use strict;
use warnings 'all';
use File::Basename;
...
my $fileName = File::Basename->fileparse($filePath);
print("$filePath\n");
print("$fileName\n");
And output is:
a/b/c/d.bin
File::Basename
What did I do wrong?
The
fileparseis not a method; it is a function. This function is exported by default, so you actually want to doYou have used is as a method call. Here
File::Basename->fileparse($filePath)is equivalent tobecause in a method invocation, the invocant (usually an object; here the package name) becomes the first argument. This is wrong, as it treats
"File::Basename"as the path to parse, and the following arguments as a list of valid suffixes.If you want to use the
fileparsefunction without exporting it to your namespace, you could