in reply to Run 2 Subroutines after a die

here is another way of doing things ;) unfortunately i was unable to implement it - it just did not work - but i know it is possible:

the Fatal.pm module allows to make some function calls die if they return undef - handy for e.g. open etc. i thought i could do this for the die call for myself (for example, call two functions named One () and Two () before dieing :), looked at the modules source - the rest can be read above...

perhaps one can put here the correct way of doing this? or is this way considered more harmful?

Replies are listed 'Best First'.
Re: Re: Run 2 Subroutines after a die
by kabel (Chaplain) on Oct 03, 2002 at 19:52 UTC
    ok here is another way that is not like the one i found in Fatal.pm, but it seems to work either.

    use strict; use warnings; use subs qw(die); # install my new die code sub die { One (); Two (); print "Die.\n"; CORE::die @_; } my $filename = "this file does not exist"; open (FH, $filename) or die "$filename: $!"; # do something close (FH); sub One { print "One . ";} sub Two { print "Two . ";}