Perl function to normalize path with spaces?
<p>I'm in maintenance mode and I'm working with a Perl script that is run on Apple, Linux, Windows and Unix. Some Apple and Linux and most Windows have spaces in the path. On Windows, the long file name needs quotes. On Apple and Linux the space needs a backslash. If there's no space, then nothing needs to be done.</p>

<p>Perl's <a href="http://perldoc.perl.org/File/Copy.html" rel="nofollow noreferrer"><code>File::Copy</code></a> and <a href="http://perldoc.perl.org/File/Spec.html" rel="nofollow noreferrer"><code>File::Spec</code></a> are aware of system differences and it abstracts them for different file systems. Looking through the other <code>File</code> functions, I don't see what is used to normalize or canonicalize a pathname which adds quotes, slashes, moves quotes around, etc. as required.</p>

<p>Perl version requirements are v5.10. So I should be able to expect at least v5.10 without any trouble.</p>

<p>What is the Perl function to normalize or canonicalize path with spaces?</p>

<hr>

<p>Here's an oversimplified example on Windows:</p>

<pre><code>my $testcat = catfile(catdir("\"C:\\Program Files\"", "My Program"), "test.txt");
print "Test cat: $testcat\n";
</code></pre>

<p>The result is the following. Notice the quoting is not right and the path separator is wrong.</p>

<pre><code>Test cat: "C:/Program Files"/My Program/test.txt
</code></pre>

<p>Here is what I expert on a Windows system (or an error):</p>

<pre><code>Test cat: "C:\Program Files\My Program\test.txt"
</code></pre>

<hr>

<p>There are similar questions, but they all seem to be one-off. For example <a href="https://stackoverflow.com/q/4285989/608639">How to handle filenames with spaces?</a> says to manually add quotes for Windows. I'm looking for the Perl routines to do it.</p>