Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

perl + return code 1 from perl script

Tags:

perl

in my little perl script (test.pl) I do the following in order to exit from program if EXIT_STATUS equal to 1

   if ( $EXIT_STATUS  == 1  )
       {
            system (exit);
      }

but I need also to get from the test.pl return code 1

for example

./test.pl

echo $?

how to enable return code 1 if EXIT_STATUS = 1 ?

lidia

like image 579
lidia Avatar asked Sep 23 '26 05:09

lidia


1 Answers

That's not how you should exit in perl. It's:

if ($EXIT_STATUS == 1) {
    exit 1;
}

and if you want to exit normally otherwise:

if ($EXIT_STATUS == 1) {
    exit 1;
}
else {
    exit 0;
}

or (depending on your intention) more simply:

exit $EXIT_STATUS;

see: http://perldoc.perl.org/functions/exit.html

like image 165
slebetman Avatar answered Sep 26 '26 01:09

slebetman



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!