在OS X 10.8.4,在測試Perl程序:爲什麼Perl不能找到File :: BaseName-> fileparse?
#!/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給出:
這是 達爾文線程多建的Perl 5,第12版,顛覆4(v5.12.4) 2level
而且@INC包括/System/Library/Perl/5.12/和 /System/Library/Perl/5.12/File/BaseName.pm存在,並在 已fileparse它。
萬一有幫助,當我使用File::Spec
,並參考File::Spec->splitpath
,工作正常(但我必須把全行)。
的[Perl模塊,方法調用可能重複:不能調用方法「X」上爲$未定義的值{SOMEFILE}線$ {SOMELINE}](http://stackoverflow.com/questions/3597605/perl-module-method-calls-cant-call-method-x-on-an-undefined- value-at-somef) – Barmar
PBP:對正則表達式使用斜槓或大括號:'qr {\。 [^ \。] * \ z} msx' – shawnhcorey
這不是Barmar鏈接到的問題的重複內容,請不要投票結束。 – daxim