in reply to exit() calls END{} blocks, but these blocks can exit()

What exit does inside of an END block is set the exit value ($?) and exits the remainder of that END block, any remaining END blocks are still called in reverse order of definition.
print "Hello World\n"; exit 0; print "Goodbye World\n"; END{ print "End 1\n"; } END{ print "End 2\n"; exit 1; print "End of End 2\n"; } END{ print "End 3\n"; } # output: Hello World End 3 End 2 End 1 # exit status: 256

Replies are listed 'Best First'.
Re: Re: exit() calls END{} blocks, but these blocks can exit()
by meonkeys (Chaplain) on Jul 08, 2002 at 19:30 UTC
    Thank you, this example explains a lot. From your example I get an exit status of 1, however. I'm checking the exit status like so:
    $ perl -Tw check_exit.plx; echo $?
    I don't know if it's relevant, but I'm using Linux.

    ---
    "A Jedi uses the Force for knowledge and defense, never for attack."