strange behavior in File::Basename

From: perl coder (perlcdr_at_mail.rumania)
Date: 07/22/04


Date: Thu, 22 Jul 2004 16:32:58 GMT

I'm using Perl 5.6.1 on Debian Linux 3.0

I noticed the module File::Basename doesn't behave like the shell
commands basename/dirname in a special case that's not described in the
module's documentation.

When a full directory path is given to the shell commands, the result is
consistent, no matter if the path ends with a trailing / or not:

$ dirname /usr/local/; basename /usr/local/
/usr
local
$ dirname /usr/local; basename /usr/local
/usr
local

When a full directory path is given to File::Basename, the result only
makes sense when the path does not contain a trailing / character:

$ perl -MFile::Basename -we '$p="/usr/local/"; print dirname($p),"\n",basename($p),"\n";'
/usr

$ perl -MFile::Basename -we '$p="/usr/local"; print dirname($p),"\n",basename($p),"\n";'
/usr
local

If the given path ends in /, then the final path element dissapears!
Unless I'm writing code for the great Houdini, I think this is a bug,
what do you think? :-)

-- 
No crazy stuff in my email. ;-)


Relevant Pages

  • Re: callc system
    ... I don't see any trailing blanks in any of your file names. ... I mean the actual file names - not the value of the Fortran variable. ... does invoke a shell. ...
    (comp.lang.fortran)
  • Re: How can I make find recurse in alphabetic order?
    ... You should ALWAYS use quotes, without the quotes, it is simply ... don't even need to do a command substitution (which, btw fails ... if the current directory path ends in a newline character). ... But given that in that case it's the shell that builds up the ...
    (comp.unix.shell)
  • Re: How to use regular expresion when doing string operations? (bash)
    ... I would like to get rid of trailing '/' in $src, ... up with 'a/b/c'. ... IIRC some versions of bash (but it could be some other shell, ...
    (comp.unix.shell)
  • Re: strange behavior in File::Basename
    ... > commands basename/dirname in a special case that's not described in the ... > module's documentation. ... > When a full directory path is given to the shell commands, ... Maybe it's a bug, but it's too late to change it --- existing scripts ...
    (comp.lang.perl.modules)
  • Re: desktop clearning
    ... you need to get rid of the marks around the directory path. ... won't work in a shell. ...
    (Ubuntu)