Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Don't blame Windows for your problems. Linux is much more lax, and the only character it prohibits from its file names is NUL.</p> <p>It isn't clear exactly what you are asking. Did you publish your code for a critique, or are you having problems with it?</p> <p>As for the specific questions you asked,</p> <ul> <li><p><em>What other characters besides spaces, parenthesis should be translated?</em></p> <p>Windows allows any character in its filenames except for control characters from 0x00 to 0x1F and any of <pre>&lt; > \ / * ? |</pre></p> <p><code>DEL</code> at 0x7F is fine.</p> <p>Within the ASCII set, that leaves <pre>! # $ % &amp; ' ( ) + , - . : ; = @ [ ] ^ _ ` { } ~ </pre></p> <p>The set of characters you need to translate depends on your reason for doing this. You may want to start by excluding non-ASCII characters, so your code should read something like</p> <p><code>$name2 =~ tr/\x21-\x7E/-/c</code></p> <p>which will change all non-ASCII characters, spaces and DEL to hyphens. Then you need to go ahead and fix all the ASCII characters that you consider <em>undersirable</em>.</p></li> <li><p><em>What other file attributes (besides file type (file/dir) and permissions) should be checked?</em></p> <p>The answer to this has to be <em>according to your purpose</em>. If you are referring only to whether renaming a file or directory as required is <em>possible</em>, then I suggest that you just let <code>rename</code> itself tell you whether it succeeded. It will return a <em>false</em> value if the operation failed, and the reason will be in <code>$!</code>.</p></li> <li><p><em>Does Perl offer a pushd/popd equivalent, or is chdir a reasonable solution to traversing the directory tree?</em></p> <p>If you want to work with that idiom, then you should take a look at <a href="https://metacpan.org/module/File%3a%3apushd" rel="nofollow"><code>File::pushd</code></a>, which allows you to temporarily <code>chdir</code> to a new location. A <code>popd</code> is done implicitly at the end of the enclosing block.</p></li> </ul> <p>I hope this helps. If you have any other specific questions then please make them known by editing your original post.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload