Code of inter.pl
is:
use strict;
use warnings;
my $var1=`cat /gra/def/ment/ckfile.txt`; #ckfile.txt doesn't exist
print "Hello World";
exit 0;
When I execute inter.pl ( perl inter.pl), and check the exit status, I see it as 0. I know the reason why it comes out as 0 because it is a backtick that is executing it in a child xterm and then returning back after execution. So, exit status not equal to 0 would be seen in the child xterm.
But, what I want is that when anything goes wrong anywhere in the script, either within the script executing inside system command or backtick or in the main script, it should exit there and then with exit status not equal to 0.
Like here, as ckfile.txt isn't present, so ` cat /gra/def/ment/ckfile.txt` would give some error. Now, as it is an erroneous command in the script, the script should exit with status != 0. (Currently, it is exiting with status == 0.)
How can it be implemented?