First off, these are from my experiences trying the same thing, they may not be the best answers, but they do work for me.
1. END block.
2. To make sure you still exit with the return value that got you into the END block, make sure to put local $?; at the beginning of your end block.
If you don't do this, the return value of the last thing you do in the end block will be the return value back to the caller of the script (which for me is Autosys and it was causing a script that should have been returning failure to return success because my last statement was a successful print to STDERR that my script was returning failure.
3. The way I accomplished this was in my parent to have a my $_PARENT_PID = $$; as a global variable. Then in the END block, you can check:
if( $$ == $_PARENT_PID ) {
# parent
}
else {
# child
}
Like I said, not the best way, but it worked. Maybe someone else will have some better solutions.
best of luck... |