Scarborough has asked for the wisdom of the Perl Monks concerning the following question:

We are working on a migration of scripts in SCL to PERL. I'm no main frame expert so how this works I'm not completely sure but in essence there is a statement as follows:

WHENEVER RESPONSE CLEANUPSUB

(For any mainframe guys out there I may have the syntex wrong but I don't have the code in front of me right now) As I understand this the whenever command monitors the (sort of globel) variable RESPONSE and if it becomes positive imediatly goes to the cleanup sub. I think maybe that $SIG{__DIE__} might be the way to replicate this behavior but has anyone any other ideas

Replies are listed 'Best First'.
Re: Something like an object node
by Joost (Canon) on Sep 09, 2004 at 10:28 UTC
      Thanks for that, its time I understood tie I've sort have put it off until now.
Re: Something like an object node
by hv (Prior) on Sep 09, 2004 at 13:13 UTC

    If the intention is to ensure some cleanup code is executed even on abnormal exit, I'd suggest translating to a slightly different approach: in the code, rather than setting a variable on error simply call die(), and specify the cleanup in an END block:

    END { # your cleanup code here } ... open($fh, '<', $file) or die "Couldn't open $file: $!";

    The END block will be executed before the script exits, even after a die(), as long as it isn't bypassed either with a POSIX::_exit() or a core dump.

    Using a tied variable to trigger this sort of behaviour involves much subtler action-at-a-distance that would tend (in my experience, at least) to make code much harder to maintain.

    Hugo

Re: Something like an object node
by Scarborough (Hermit) on Sep 09, 2004 at 16:21 UTC
    Thanks for all the great advice. I have looked at tie (at last) and yes I got what I needed from that. I've messed around with Hugo's idea before and I agree its much easier to understand but in this instance tie works out right.

    However I've found it very difficult to explain to my boss!