I have a code snippet:
my @array=("abc","def", "ghi");
print "I am testing exit code\n";
grep /lan/, @array;
if ($?) {
print "status is 0\n";
}
else {
print "Status is 1\n";
}
I am getting "status is 1" in output, but I want "status is 0". As per my understanding, in @array, "lan" is not found and hence exit status must be non-zero, and thus "status is 0" should be printed.
Why is Perl not giving the right exit code? Please give a correct idea about the exit code theory if I am wrong as per my understanding above?