in reply to Re^2: Any way to simulate a Windows path handling for File::Spec without Windows?
in thread Any way to simulate a Windows path handling for File::Spec without Windows?

That will work on POSIX, where the volume is null, and on Windows, where the volume is syntactically equivalent to a leading directory name. If I recall correctly, that will not work on VMS, where the filename syntax clearly distinguishes between volume, directories, and (leaf) filename, and there may be other systems where that also breaks. It is best to go all the way with File::Spec if you can.

Of course, if you do not care about portability to VMS, that will not be a problem. :-)

  • Comment on Re^3: Any way to simulate a Windows path handling for File::Spec without Windows?
  • Download Code

Replies are listed 'Best First'.
Re^4: Any way to simulate a Windows path handling for File::Spec without Windows?
by nysus (Parson) on Sep 08, 2019 at 06:06 UTC

    I'm doing my best to try to use File::Spec but it's giving me headaches when the same method gives me different results on different platforms. PIA. I'll probably just change the algorithm so it looks at raw file path strings instead of directory components. It'll be slightly slower but I won't have to worry about this nonsense.

    $PM = "Perl Monk's";
    $MCF = "Most Clueless Friar Abbot Bishop Pontiff Deacon Curate Priest Vicar";
    $nysus = $PM . ' ' . $MCF;
    Click here if you love Perl Monks

      The reason that File::Spec gives different results on different platforms is that File::Spec is intended to adapt to the platform that your program is running on — and different platforms expect different filenames!

      If you are only processing filenames within your program, and do not need to map back from these "internal names" to file names (because you are storing the actual local filenames separately), you could use File::Spec to split the names and then specifically use File::Spec::Unix on all platforms to construct *nix-style "internal names" for processing. If I understand correctly, File::Spec::Unix will load on all platforms, so it is always available.

        That's a good suggestion. But I have already changed the algorithm which is no longer dependent upon File::Spec and released a new version of the module.

        $PM = "Perl Monk's";
        $MCF = "Most Clueless Friar Abbot Bishop Pontiff Deacon Curate Priest Vicar";
        $nysus = $PM . ' ' . $MCF;
        Click here if you love Perl Monks