On OS X 10.8.4, in a test perl program:
#!/usr/bin/perl
use warnings;
use strict;
use File::BaseName;
my $fname = "/usr/local/junk.txt";
my ($name, $path, $suffix1) = File::BaseName->fileparse($fname, qr'\.[^\.]*');
Any ideas why I get the error message:
Can't locate object method "fileparse" via package "File::BaseName"
(perhaps you forgot to load "File::BaseName"?)
For that matter, why do I need to put File::BaseName
? If I don't, it says
Undefined subroutine &main::fileparse
perl -v gives:
This is perl 5, version 12, subversion 4 (v5.12.4) built for darwin-thread-multi-2level
And @INC includes /System/Library/Perl/5.12/ and /System/Library/Perl/5.12/File/BaseName.pm exists and has fileparse in it.
In case it helps, when I Use File::Spec
and refer to File::Spec->splitpath
, that works fine (but I do have to put the full line).
It's case sensitivity:
Basename
is written with lowercase letter "N". Acme::require::case will prevent that problem.
Besides, you don't have to use a qualified name for fileparse
after you've imported the File::Basename
module:
#!/usr/bin/perl
use warnings;
use strict;
use File::Basename; # !!!
my $fname = "/usr/local/junk.txt";
my ($name, $path, $suffix1) = fileparse($fname, qr'\.[^\.]*'); # !!!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With