Loading ...
Sorry, an error occurred while loading the content.

Re: [PBML] system() call in END() subroutine overrides script exit value

Expand Messages
  • merlyn@stonehenge.com
    ... Kelly Mon May 17 11:09:43 MDT 2010 Kelly 0 Kelly In other words, the return value of the date command in an END subroutine Kelly overrides my desired
    Message 1 of 2 , May 17 11:18 AM
    • 0 Attachment
      >>>>> "Kelly" == Kelly Jones <kelly.terry.jones@...> writes:

      Kelly> I did this in tcsh:
      >> perl -le 'exit(2); sub END {system("date");}' ; echo $status
      Kelly> Mon May 17 11:09:43 MDT 2010
      Kelly> 0

      Kelly> In other words, the return value of the date command in an END subroutine
      Kelly> overrides my desired exit value.

      Kelly> How do I fix this? I want to tell Perl: if I explicitly do exit($foo), I
      Kelly> want the script to exit with status $foo?

      Add "local $?" to the beginning of your END block. Then, nothing within
      that block can affect your exit status.

      --
      Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
      <merlyn@...> <URL:http://www.stonehenge.com/merlyn/>
      Smalltalk/Perl/Unix consulting, Technical writing, Comedy, etc. etc.
      See http://methodsandmessages.vox.com/ for Smalltalk and Seaside discussion
    Your message has been successfully submitted and would be delivered to recipients shortly.