Due to some messed up legacy code,
I have
$path = [OS specific base DIR name][hardcoded Linux file path]
So on Linux, it is something like
$path = /common/path/to/dir/pathtofile/name.extension
but on Windows it becomes this
$path = C:\path\to\dir\pathtofile/name.extension
Some of the code fails on Windows because it is expecting a \ while it gets a /.
Is there a Perl function that can help me here?
Something like
print "$path\n";
$path = <some function> $path;
print "$path\n";
C:\path\to\dir\pathtofile/name.extension
C:\path\to\dir\pathtofile\name.extension
The
File::Specfamily of modules exists exactly for that reason. You might want to consider using that instead of hardcoding unix paths.If you really need to hardcode unix paths somewhere, which really doesn’t seem like a good idea, you should probably use
File::Spec::Unixto split up the path into its components, and then use theFile::Specvariant native to your target system to build put the components back together again.