Path: utzoo!utgpu!watserv1!watmath!att!att!linac!pacific.mps.ohio-state.edu!zaphod.mps.ohio-state.edu!wuarchive!mit-eddie!uw-beaver!zephyr.ens.tek.com!tektronix!sequent!mntgfx!lisch From: lisch@mentor.com (Ray Lischner) Newsgroups: comp.lang.perl Subject: better idea for atexit Message-ID: <1990Nov9.005202.18300@mentor.com> Date: 9 Nov 90 00:52:02 GMT Organization: engr Lines: 32 After thinking about the problem a little, I decided I prefer a different way of having cleanup handlers. I suggest there be an array, @EXIT. The user adds subroutine names to @EXIT. Before exiting, Perl goes through @EXIT, in order, and calls each subroutine with no arguments. An @EXIT handler is not allowed to modify @EXIT, and the exit and die operations are ignored inside an @EXIT subroutine. The user can control the order of the cleanup handlers, usually by appending to @EXIT with push, or inserting a handler at the beginning of the list, with unshift. A package can add a cleanup handler without bothering the user of the package with such details. For example: package number1; sub cleanup { unlink($lock_file); } push(@EXIT, "number1'cleanup"); package curses; &initscr; sub cleanup { &endwin; } push(@EXIT), "curses'cleanup"); -- Ray Lischner UUCP: {uunet,apollo,decwrl}!mntgfx!lisch