macos – 为什么Perl不能找到File :: BaseName-> fileparse?

前端之家收集整理的这篇文章主要介绍了macos – 为什么Perl不能找到File :: BaseName-> fileparse?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
在OS X 10.8.4上,在测试perl程序中:

#!/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'\.[^\.]*');

我收到错误消息的任何想法:

Can't locate object method "fileparse" via package "File::BaseName"
(perhaps you forgot to load "File::BaseName"?)

就此而言,为什么我需要放置File :: BaseName?如果我不这样做,它说

Undefined subroutine &main::fileparse

perl -v给出:

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.

如果它有帮助,当我使用File :: Spec并参考File :: Spec-> splitpath时,它工作正常(但我必须把整行).

解决方法

区分大小写:
Basename用小写字母“N”写成. Acme::require::case将防止这个问题.

此外,在导入File :: Basename模块后,您不必为fileparse使用限定名称

#!/usr/bin/perl

use warnings;
use strict;
use File::Basename; # !!!

my $fname = "/usr/local/junk.txt";
my ($name,$suffix1) = fileparse($fname,qr'\.[^\.]*'); # !!!

猜你在找的Perl相关文章