strange behavior in File::Basename

Ask a Question related to PERL Modules, Design and Development.

  1. #1

    Default strange behavior in File::Basename

    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. ;-)
    perl coder Guest

  2. Similar Questions and Discussions

    1. Strange behavior when saving a file
      I'm using Illustrator 10.0.3, Mac OS 10.2.8. When I make changes to one of my Illustrator files and save it, it makes a copy of that file to the...
    2. Very strange file upload behavior
      I tried to search for this issue on the group, but don't even know where to start, so here's my problem. We have a very simple form which has a...
    3. File::Basename
      From how I understood it file::basename was able to tell figure out the filename without path for both windows and UNIX. I have an html page that...
    4. Strange behavior after reading big file
      I have a piece of code that looks something like this: my %hash; my $i = 0; open HUGE, 'Huge_File' or die '>*choke*<'; $| = 1; print "\n"; for...
    5. File.basename, dirname and split changed in 1.8.0!
      Why did the behaviour of File.basename, File.dirname and File.split change in ruby 1.8.0? The tests below run on 1.6.8( and 1.7.x, I think), but...
  3. #2

    Default Re: strange behavior in File::Basename

    perl coder <perlcdr@mail.rumania> writes:
    > 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:
    [url]http://user.cs.tu-berlin.de/~eserte/src/perl/WWWBrowser/[/url]
    Slaven Rezic Guest

  4. #3

    Default Re: strange behavior in File::Basename

    On 2004-07-22, Slaven Rezic <slaven@rezic.de> wrote:
    > perl coder <perlcdr@mail.rumania> writes:
    >>
    >> $ 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.
    Ilmari Karonen Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139