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

I found out today, that catfile('') results in a nullstring on Perl 5.7 and Perl 5.10, but returns \ on Perl 5.8.8. The documentation of cpan:File::Spec::Win32 gives no information about this border case. Researching the issue a bit, I came accross the following Perl bug filed for Perl 5.8.8 which seems to cover this case: http://rt.perl.org/rt3//Public/Bug/Display.html?id=41439.

Interestingly, the bug was rejected, on the grounds that

I don't want to object the validity of these arguments, but I wonder why - if this is not a bug - this has been changed back to the old behaviour in 5.10. My conclusion for this would be to simply ensure that catfile or catdir is not called with empty path components (because the behaviour seems to be undefined). Do other Monks see it the same, or did I miss a point?

-- 
Ronald Fischer <ynnor@mm.st>

Replies are listed 'Best First'.
Re: File::Spec::Win32::catfile behaviour for empty path components
by ikegami (Patriarch) on Nov 05, 2008 at 10:33 UTC

    if this is not a bug - this has been changed back to the old behaviour in 5.10.

    I can't find anything in CHANGES about the changes in behaviour. Both changes in behaviour are possibly side-effects of other changes. The effect of changes probably isn't tested against invalid inputs such as the one you presented.

    Ref:
    Changes up to 3.29

    5.8.7 comes with version 3.05 5.8.8 comes with version 3.12 5.10.0 comes with version 3.2501
Re: File::Spec::Win32::catfile behaviour for empty path components
by syphilis (Archbishop) on Nov 05, 2008 at 10:10 UTC
    I found out today, that catfile('') results in a nullstring on Perl 5.7 and Perl 5.10, but returns \ on Perl 5.8.8

    I get the same as your for perl-5.8.8, but for perl-5.10.0 I get:
    C:\>perl -MFile::Spec -e "print File::Spec::Win32::catfile('')" Can't call method "canonpath" without a package or object reference at + C:/_32/ap1004/lib/File/Spec/Win32.pm line 130. C:\>
    Given that the catdir documentation specifies "Concatenate two or more directory names...", and that I failed to provide "two or more directory names" as arguments, I think it's reasonable that I got an error - though perhaps it would be clearer if catdir were to count the arguments received, and then reject my code on the basis of "insufficient arguments".

    Cheers,
    Rob

    Update: Yep, if I call catfile as a method on 5.10.0 then I get the same as the OP.

      That error you are getting is unrelated to the topic brought up by the OP. catfile should be called as a method:

      >perl580\bin\perl -MFile::Spec -le"print File::Spec::Win32->catfile('' +)" >perl588\bin\perl -MFile::Spec -le"print File::Spec::Win32->catfile('' +)" \ >perl5100\bin\perl -MFile::Spec -le"print File::Spec::Win32->catfile(' +')" >

      But I agree with your analysis. In short, GIGO.

      You did not call catfile in the right way. If you don't drag it in via File::Spec::Functions, you need to call it like this:

      c:\perl\bin\perl -MFile::Spec -e "print File::Spec::Win32->catfile('') +"
      which prints the empty string (in Perl 5.10 and in Perl 5.7).

      -- 
      Ronald Fischer <ynnor@mm.st>