I want to get the current OS directory separator into a var so that I can use it in string substitution.On some platforms, there is not a single separator. VMS for example has the syntax
Although '.' is the separator between components of the path, the whole directory is encased in brackets.DEVICE:[DIR.PATH]FILENAME.EXT;VER
I advise going with what others suggest, with File::Spec and File::Spec::Functions. Note that the functions splitpath and splitdir do what you are looking for, returning a list of path elements (list context). You can work on the list of strings and join them back together again with catpath or catdir.
Note that all O/S that run Perl support POSIX filenames, which means that you can use forward slash as a directory separator. This is how the standard module installs work, supplying filespecs such as t/mytest.t and -Iblib/lib.
Also note that usually you cannot mix native and POSIX directory separators (Windows lets you get away with it sometimes). So to write portable code that works with native filespecs, I recommend sticking to File::Spec.
See also the slides for a talk I gave recently on portability.
--
I'm Not Just Another Perl Hacker
In reply to Re: Platform independant directory separator
by rinceWind
in thread Platform independant directory separator
by jaa
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |