You always can put your code inside an eval, but if you want to really make die() work like warn(), even for outside code, and keep the app running, you need to overwrite the die() function.
Soo, here I show you an example of how to do that, and note that the BEGIN code, need to be loaded before compile any other code. Soo, this BEGIN code need to be the first thing in your script, since what is compiled before overwrite the die() function, won't keep the overwrite reference:
As we can see, if you make die() work like warn(), a die() that is made inside an eval() won't work like generally we want, that is to go out of the eval. Soo, we need to handle that too, using the predefined variable $^S:sub BEGIN { *CORE::GLOBAL::die = \&DIE_2_WARN ; $SIG{__DIE__} = \&DIE_2_WARN ; } sub DIE_2_WARN { warn(@_) ;} die("This die() won't exit!") ; print "And here we continue the app...\n" ; eval { die("die inside eval!"); print "Won't go out of eval!\n" ; } ;
Enjoy!sub BEGIN { *CORE::GLOBAL::die = \&DIE_2_WARN ; $SIG{__DIE__} = \&DIE_2_WARN ; } sub DIE_2_WARN { if ( $^S ) { CORE::die(@_) ;} else { warn(@_) ;} } die("This die() won't exit!") ; print "And here we continue the app...\n" ; eval { die("die inside eval!"); print "And this print won't be executed.\n" ; } ; print "ERROR: $@\n" ;
Graciliano M. P.
"Creativity is the expression of the liberty".
In reply to Re: Keeping perl alive after a module calls die. (making die() work like warn())
by gmpassos
in thread Keeping perl alive after a module calls die.
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |