Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You have asked a question that has multiple answers. To just put a backslash in to form a Windows path, you need to escape the backslash thus, and this will solve your direct problem:</p> <pre><code>system($v1 . "\\" . $bin . " " . $trinp); </code></pre> <p>However, there are a few refinements. Firstly, you can use Perl's interpolation to make it easier to read:</p> <pre><code>system("$v1\\$bin $trinp"); </code></pre> <p>You can also use Unix-style forward slashes, as Windows understands these, and prevents so-called "backslashitis":</p> <pre><code>system("$v1/$bin $trinp"); </code></pre> <p>A better way however is to use <a href="http://search.cpan.org/~kwilliams/Path-Class-0.32/README.pod" rel="nofollow">Path::Class</a> to generate paths on any operating system.</p> <p>Further, there is a potential security problem in your code that can be caused if $trinp (or any of the other variables) contains shell metacharacters such as <code>|</code> to pipe into another command. If you provide a list of arguments to the system() function, it will pass those directly to the command instead of the shell. You will probably also want to check if the command was successful, and do something useful (e.g. die()ing) if it failed:</p> <pre><code>system("$vi/$bin", $trinp) == 0 or die "Couldn't run $vi/$bin: $!"; </code></pre> <p>I'll leave it as an exercise for you to convert my final example to use Path::Class.</p> <p>[Edited to correct misuse use of system(), which returns the status of the command that was run which is zero for success. I confused it with more common other Perl functions which return nonzero for success.]</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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