in reply to die command while other files are opened

Hello hatz,

I'm not sure what would happen if my program exits before my close() command because of other reasons such as another file that cannot be opened (the famous "open $bar or die")

Put the close command in an END { ... } block. Code in END blocks runs when the program terminates, even if the termination is caused by an uncaught exception or an exit command:

12:55 >perl -wE "END { say 'Bye!' } say 'Hi!'; die 'D\'oh!';" Hi! D'oh! at -e line 1. Bye! 12:55 >perl -wE "END { say 'Bye!' } say 'Hi!'; exit 0;" Hi! Bye! 12:55 >

See perlmod#BEGIN, UNITCHECK, CHECK, INIT and END.

Hope that helps,

Athanasius <°(((><contra mundum Iustus alius egestas vitae, eros Piratica,

Replies are listed 'Best First'.
Re^2: die command while other files are opened
by hatz (Initiate) on Dec 06, 2015 at 15:10 UTC

    Thank you for your answer.

    I am going to use this END function.

    END { close(LOG) if (tell(LOG) != -1);} This looks perfect!