On Jul 28, Keenan, Greg John (Greg)** CTR ** said:

sub getDate {
print "start date\n";
if ( system("/bin/date") ) {
  print "can't get date\n";
  exit(2);
}
print "finish date\n";
}

system() executes a command, and returns the shell's error code. 0 indicates success, non-0 indicates failure. It does NOT return the output. If output is produced from the program, it's printed to STDOUT.

sub getDate {
print "start date\n";
if ( `/bin/date` ) {
  print "can't get date\n";
  exit(2);
}
print "finish date\n";
}

Backticks execute a command and return its output. Since the return value is true in this case, the if() statement's condition is true, and you call exit().

If system() or ``s fail, you should check $! to see the error message.

--
Jeff "japhy" Pinyan         %  How can we ever be the sold short or
RPI Acacia Brother #734     %  the cheated, we who for every service
http://japhy.perlmonk.org/  %  have long ago been overpaid?
http://www.perlmonks.org/   %    -- Meister Eckhart

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to