sandy105 has asked for the wisdom of the Perl Monks concerning the following question:

i have a statement like this :

$rc=system("cp -p $file $back") and &unixerr_function("CP", "file", "Partial file may have been copied.");

can somebody explain why we use "AND" here instead oF usual "OR" die/error handling function

eg. open (file) or die

Replies are listed 'Best First'.
Re: a small doubt
by choroba (Cardinal) on Nov 11, 2014 at 09:26 UTC
    See system. It returns the exit code, which is traditionally 0 for success, opposite to how open returns success. For clearer code, I'd use
    if (0 != ($rc = system 'cp', '-p', $file, $back)) { unixerr_function('CP', 'file', 'Partial file may have been copied. +'); }
    لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ

      thanks , thats what i wanted to know

        Generally speaking, most built-in Perl functions return a value which indicates success, with a non-true value indicating failure (zero, empty string, or undef). Many user-written Perl functions follow the same convention.

        System commands in Unix, Windows, etc., will result in a numeric exit value indicating an error, with zero indicating no error.