[plug] Perl $? equivalent

Ryan ryan at is.as.geeky.as
Fri Mar 12 13:50:53 WST 2004


On Fri, 2004-03-12 at 13:41, Jay Turner wrote:
> Hi All,
> 
> Can anyone tell me what (if any) the Perl equivalent to Bash's '$?' is.
> 
> 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.

use system and read its return value:

#!/usr/bin/perl
use strict;
my $return = system('cat','/etc/hosts');
print "return: $return\n";

=========
the above returns 0, if you specify an unknown command it returns -1 and
if the command runs and returns error, you get that error, for example
if you cat a non existent file, you get 256.

Ryan




More information about the plug mailing list