in reply to Unify windows filenames

There are some subtleties in handling this sort of thing across different OS's. As you've indicated, using Windows file paths in Perl leads to lots of "synonymy" (different ways of expressing the same path: all-lower-case == mixed-case == all-upper-case, "\" == "/" ), whereas on linux and "traditional" unix, there is no such "synonymy": if two path strings differ in any way on any one character, they represent distinct paths/files.

And then there's the macosx adaptation of openBSD unix, where (in contrast to every other type of unix-based or unix-like OS I know of) case distinctions are ignored. I just tried this on my mac, and was quite saddened by the result:

$ echo foobar > /tmp/junk $ cat /tmp/junk foobar $ cat /tmp/JUNK foobar $ echo hello > /tmp/JUNK $ cat /tmp/junk hello $ cat /tmp/JUNK hello
I see that File::Spec has a "case_tolerant()" function, which (according to the man page) is supposed to return "a true or false value indicating, respectively, that alphabetic case is not or is significant when comparing file specifications."

But having tried that just now on macosx, I find that it returns false (case is significant), despite the fact that case is demonstrably not significant for distinguishing paths on macosx. I think that's something that needs to be fixed in File::Spec.

(I'm still using the Perl 5.8.8 that shipped with macosx 10.5.8 -- maybe this was fixed in Perl 5.10?)

So to succeed in your cross-platform intentions, you yourself have to check the value of $^O -- if it's "darwin", you have to fold case; if it's "MSWin32", you have to fold case and slashes; anything else, you leave all characters as-is.

(updated to fix link to module page)
(updated to change "mswin" to "MSWin32", which is what File::Spec looks for)

Replies are listed 'Best First'.
Re^2: Unify windows filenames
by Anonymous Monk on Sep 20, 2009 at 02:40 UTC
      Ah -- right, of course. Okay, I got that, and it isn't fixed. Guess I should report to the maintainer -- I think the fix in "File/Spec/Unix.pm is pretty simple:
      193c193 < sub case_tolerant { 0 } --- > sub case_tolerant { ( $^O eq 'darwin' ) ? 1 : 0 }

      There's even more strangeness about the darwin path/name "logic": the bash shell's file-name completion function is case-sensitive, even though the underlying OS file-name handling is not. So for most of the command-line stuff I do (which is most of what I do), it feels (and I have to type) as if the file names are case-sensitive, even though they aren't. Go figure.

        Even this isn't enough. You can have a case sensitive file tree on Darwin, you just have to ask for it as it's not the default. :(

        I think the idea is to create File::Spec::Darwin