Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

File::Basename Can't Recognize its Function in Darwin/MacOS Leopard

by neversaint (Deacon)
on Jun 18, 2008 at 05:14 UTC ( [id://692616]=perlquestion: print w/replies, xml ) Need Help??

neversaint has asked for the wisdom of the Perl Monks concerning the following question:

Dear Masters,
I have the following script
use File::Basename; my $gds_file = "data/myfile.soft"; my $base = basename($gds_file,".soft");
But somehow File::Basename fail to recognize the "basename" function. By giving:
$ perl mycode.pl Undefined subroutine &main::basename called at mycode.pl line 3.
Although my code apparently can identify the path location of File::Basename library. Since 1) It has no path error message after execution and 2) perldoc File::Basename can show the content.

Is there a way to enable my code to recognize the function?

---
neversaint and everlastingly indebted.......

Replies are listed 'Best First'.
Re: File::Basename Can't Recognize its Function in Darwin/MacOS Leopard
by graff (Chancellor) on Jun 18, 2008 at 05:25 UTC
    Works for me:
    $ perl -MFile::Basename -le '$f="data/myfile.soft";$b=basename($f,".so +ft"); print $b' # output: myfile
    (macosx 10.5.3, perl 5.8.8 built for darwin-thread-multi-2level)

    When I first saw your post, I noticed the "i" in "File::Basename" was in upper case -- it appears you fixed that in the post, but if it is not fixed in the script, perl would be able to "locate" the module file (because macosx can still ignore case when looking up paths), but perhaps perl would not be able to match the module name in the script to the path name (because of I vs. i).

Re: File::Basename Can't Recognize its Function in Darwin/MacOS Leopard
by grinder (Bishop) on Jun 18, 2008 at 06:13 UTC

    For some reason the import() routine is not being run, and so the function is not injected into your namespace.

    As a simple matter of code hygiene, you could explicitly state what you want exported from File::Basename: use File::Basename 'basename';

    And who knows, it might fix your problem. If it still fails to work, does the following work?

    my $base = File::Basename::basename($gds_file,".soft");

    If that still fails to work, does perldoc -m File::Basename show you something that resembles the code of the module itself?

    • another intruder with the mooring in the heart of the Perl

Re: File::Basename Can't Recognize its Function in Darwin/MacOS Leopard
by Anonymous Monk on Jun 18, 2008 at 06:12 UTC
    See what END { print $_,$/ for %INC; }prints
Re: File::Basename Can't Recognize its Function in Darwin/MacOS Leopard
by rovf (Priest) on Jun 18, 2008 at 10:32 UTC
    I don't know why it is not imported (you could have a look at the code, with
    perldoc -m File::Basename
    to make sure that really the correct module is located, and whether basenam is in @EXPORT), but did you already try whether
    use File::Basename qw(basename);
    works?
    -- 
    Ronald Fischer <ynnor@mm.st>

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://692616]
Approved by Erez
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (2)
As of 2024-04-20 03:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found