Firstly, I need to run 2 subroutines if my open fails, the code I have come up with works but seems clumsy.
This looks like an appropriate spot to use $SIG{__DIE__}.
{ local $SIG{__DIE__} = sub { One(); Two(); die shift; }; open TST, ">>$var1" or die "Can't open file: $!"; }
The code would also run if your script dies in the block for an unforeseen reason. Well, I can't imagine anything that could cause it in this simple example :-) but it's a useful technique for the toolbox.
In reply to Re: Run 2 Subroutines after a die
by bart
in thread Run 2 Subroutines after a die
by AcidHawk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |