system uses the shell when you call it with one argument. It doesn't do that when you call it with a list.
The Perl Cookbook suggests code like this:
my $status = system($program, $arg1, $arg2);
die "$program exited funny: $?" unless $status == 0;
I would expect the array to flatten into a list in your last example, but I wouldn't expect a list to become a single item. Which error message are you receiving? | [reply] [d/l] |
This reply was the best. Thank you so much
| [reply] |
Not that this is perl related, but if you're executing
the move command mv with the same file as both arguments,
mv should fail with an error message.
Your first invocation of system() should execute the
command just as if you had typed it into the shell. Which
can be dangerous -- if you're using the -T switch
for taint checking, the first version of system will
cause your program to die if the value of $file is obtained
from outsite the source code of your script (from a command
line argument, or from a file including stdin).
The second invocation of system() should be much safer,
as the array invocation of system() executes the first
argument, and any remaining arguments are passed directly
to the program being executed.
As already asked, what is the output of the program when
you run it? | [reply] |
system("mv \"$file1 $file1\""); | [reply] |
Thanx chromatic. Your answer was really helpful.
Mortis, sorry for confusion. I should have put mv $file1 $file2. | [reply] |
do not just use backtics! backtics should only be used when
it is absolutely crucial that you capture the output of a
program! otherwise it is wasteful, because the output
will be captured into a temporary variable (and then thrown
away...)
| [reply] |