|
Posted by perl coder on July 22, 2004, 5:32 pm
Please log in for more thread options
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. ;-)
|
|
Posted by Slaven Rezic on July 22, 2004, 10:10 pm
Please log in for more thread options
> 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? :-)
>
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
--
Slaven Rezic - slaven <at> rezic <dot> de
Start a WWW browser - OS independent:
http://user.cs.tu-berlin.de/~eserte/src/perl/WWWBrowser/
|
|
Posted by Ilmari Karonen on July 24, 2004, 11:51 am
Please log in for more thread options >>
>> $ 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.
--
Ilmari Karonen
If replying by e-mail, please replace ".invalid" with ".net" in address.
|
| Similar Threads | Posted | | Strange errors | August 9, 2004, 7:17 pm |
| XML::Twig::XPath - strange problem | November 10, 2005, 9:44 am |
| Net::SFTP / Net::SSH::W32Perl strange debug messages? | August 13, 2006, 11:06 am |
| use lib -- different behavior | August 13, 2004, 1:47 pm |
| Syntax error using cpan leads to bizarre behavior | September 10, 2004, 6:32 pm |
| Tips on module selection for shell and/or commandline 'subcommand' behavior | January 16, 2007, 5:19 am |
| ISO: deep voodoo debugging tools for tracking down seriously weird module behavior. | November 9, 2007, 1:28 pm |
| install HTML::Template - Problem reading cache file / Bad file number | July 24, 2004, 7:55 pm |
| Reading contents of an excel file from a test file | May 15, 2007, 2:49 am |
| A do-file location: how the code inside that do-file find it? | January 20, 2008, 12:32 am |
|