Wherever available, you should use LIST-style forms of command launching functions. For example, prefer system("rm", "-rf", @temp_directories) over system("rm -rf @unneeded"). The same goes for pipe-open, exec and so on.
This is because when Perl encounters a command which consists of a single string containing so called special characters it passes the whole string to the shell. And modern filesystems allow spaces in file names which are not getting escaped, and this is where your command breaks. Some filesystems even allow glob characters (like * [ ]). Even more fun: imagine creating a file called -rf ~ and trying to remove it by system("rm $filename").
Bad news: list form of open is not supported on Windows. Good news: list form of open2 is. And so is high-level IPC::Run (but I got some problems with binary files transferred via pipe when I used this module).
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|