Jose Torres wrote at Wed, 29 May 2002 20:30:06 +0200:

> Hi,
> 
> If I'm calling the diff program from within a Perl script with something like:
> 
> system("diff file1.txt file2.txt");
> 
> how can I detect if there is a result or not, since if the files are identical, diff 
>doesn't have
> any output? I need to be able to be able to determine if there was any output from 
>within my
> script so that I can take one particular action if diff returned something (the 
>files were
> different) or take another if diff didn't return anything (the files were 
>identical). Thanks for
> all help with this.
> 
When using the system command, 
it's most better to seperate the arguments from the command.
Why ? So all shell quoting are done for you.
Assume one file comes from the win - world with spaces including or so.
Why not ? It doesn't make any effort.
So you script should change to:

if (system('diff', $file1, $file2)) {
     # different
} else {
     # same
}

Cheerio,
Janek

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to