in reply to Syntax details with "system"
Yes, the two forms are different.
In the first form, a system call (eg, the C function as implemented internally by the operating system for executing commands) is made with the arguments provided. In the second form, the string is passed to the shell to deal with. The difficulty that you are running into is with escaping of meta-characters (characters special to the shell, but not special to the internal system call).
The first form (system call) is equivalent to automatically escaping all arguments. So when you say above that the first form "works", it really doesn't, as it just passes ">$output_file" as an argument to the command, which in general won't do what you want. I don't know of any way to do something like piping to a file using the first form (you normally use open() for that instead).
The second form (shell command) probably doesn't work for you because you are not escaping characters that you want escaped. Escaping can be done automatically in Perl using quotemeta() or \Q...\E.
As an example, consider:
>echo two > oneIf you want this to echo "two > one", then you need to escape the ">":
system "echo", "two", ">", "one";If you want "two" to be piped to a file called "one", then you don't:
system "echo two > one";
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Syntax details with "system"
by Anonymous Monk on Jul 20, 2012 at 17:57 UTC |