Why can't Perl find the file :: BaseName-> fileparse?

On OS X 10.8.4 in the perl test 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"?) 

In this regard, why should I put File::BaseName ? If I do not, he says

 Undefined subroutine &main::fileparse 

perl -v gives:

This is perl 5, version 12, subversion 4 (v5.12.4), built for Darwin-thread-multi-2

And @INC includes / System / Library / Perl / 5.12 / and / System / Library / Perl / 5.12 / File / BaseName.pm exists and has fileparse in it.

If this helps, when I use File::Spec and refer to File::Spec->splitpath , this works fine (but I need to put the full line).

+4
source share
1 answer

Basename Sensitivity: Basename is written in lowercase "N". Acme :: require :: case will prevent this problem.

In addition, you do not need to use the qualified name for fileparse after importing the File::Basename :

 #!/usr/bin/perl use warnings; use strict; use File::Basename; # !!! my $fname = "/usr/local/junk.txt"; my ($name, $path, $suffix1) = fileparse($fname, qr'\.[^\.]*'); # !!! 
+8
source

Source: https://habr.com/ru/post/1492552/


All Articles