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? :-)

Signature
No crazy stuff in my email. ;-)
Slaven Rezic - 22 Jul 2004 20:10 GMT
> I'm using Perl 5.6.1 on Debian Linux 3.0
>
[quoted text clipped - 25 lines]
> Unless I'm writing code for the great Houdini, I think this is a bug,
> what do you think? :-)
Maybe it's a bug, but it's too late to change it --- existing scripts
may rely on this behavior. But an additional CAVEAT section in the
File::Basename doc would be nice...
Regards,
Slaven

Signature
Slaven Rezic - slaven <at> rezic <dot> de
Start a WWW browser - OS independent:
http://user.cs.tu-berlin.de/~eserte/src/perl/WWWBrowser/
Ilmari Karonen - 24 Jul 2004 08:51 GMT
>> $ perl -MFile::Basename -we '$p="/usr/local/"; print dirname($p),"\n",basename($p),"\n";'
>> /usr
>
> Maybe it's a bug, but it's too late to change it --- existing scripts
> may rely on this behavior. But an additional CAVEAT section in the
> File::Basename doc would be nice...
It is a bug. dirname() and basename() are documented to produce the
same results on Unix as the corresponding shell commands. In this
case, they obviously don't.
Besides, the current output just makes no sense. Nobody sane would
deliberately rely on it. Fixing it would probably cure more latent
bugs than it would introduce.

Signature
Ilmari Karonen
If replying by e-mail, please replace ".invalid" with ".net" in address.