$? is the variable that holds the exit status from external commands in Perl. If you just want to know whether the command succeeded, you could do something like this:
system('whatever');
if ($?) {
warn "whatever failed\n";
}
If you want to know why the command exited with an error, you could examine the value of $? like this:
system('whatever');
if ($?) {
my $exit_value = $? >> 8;
my $signal_num = $? & 127;
my $dumped_core = $? & 128;
print "whatever exited with status $exit_value";
print " from signal $signal_num" if $signal_num;
print " and dumped core" if $dumped_core;
print "\n";
}
(See perlvar and system for more about $?) |