[plug] Perl $? equivalent

James Devenish devenish at guild.uwa.edu.au
Fri Mar 12 13:51:17 WST 2004


In message <OOECKHEBCBMDKGKDPJLHOEJGEBAA.jturner at bsis.com.au>
on Fri, Mar 12, 2004 at 01:41:22PM +0800, Jay Turner wrote:
> I am calling a program (`cat mailFile | sendmail -t`) from a perl script and
> I want to check that it has executed properly or not.
> 
> In bash I would just "if [ $? -ne 0 ]" but I don't think I can locate an
> equivalent in Perl.

Running any of the following in Perl seems to have the desired effect
(see the perlfunc documentation for 'system'):

$result = `false`;
print "Result: ".($? >> 8)."\n";
$result = `true`;
print "Result: ".($? >> 8)."\n";
$result = system('false');
print "Result: ".($result >> 8)."\n";
$result = system('true');
print "Result: ".($result >> 8)."\n";
`false`;
print "Result: ".($? >> 8)."\n";
`true`;
print "Result: ".($? >> 8)."\n";





More information about the plug mailing list