Path: utzoo!utgpu!jarvis.csri.toronto.edu!cs.utexas.edu!usc!elroy.jpl.nasa.gov!jpl-devvax!lwall From: lwall@jpl-devvax.JPL.NASA.GOV (Larry Wall) Newsgroups: comp.lang.perl Subject: Re: on exit functionality? Keywords: exit handler Message-ID: <6815@jpl-devvax.JPL.NASA.GOV> Date: 17 Jan 90 18:19:53 GMT References: <25B3E15F.25354@paris.ics.uci.edu> Reply-To: lwall@jpl-devvax.JPL.NASA.GOV (Larry Wall) Organization: Jet Propulsion Laboratory, Pasadena, CA Lines: 28 In article <25B3E15F.25354@paris.ics.uci.edu> nagel@paris.ics.uci.edu (Mark Nagel) writes: : I was rewriting an old beaten-up shell script in perl (of course) : and noticed that there's no obvious way to duplicate sh's easy way : of creating an exit handler (using trap cmd 0). Is there any way to : trap signal 0 in perl? Or is there some other exit handler : mechanism? I thought of appropriating some other signal and killing : myself with that signal number. This seems messy, but I'll do it if : there's no other way... Why not just write a sub my_exit that does your cleanup and then calls exit or die as appropriate? If you're worried about also catching errors that cause an exit, just put the whole script inside an eval: eval <<'The_End'; [Your script here.] The_End &my_exit($@); "Trap cmd 0" is just a poor man's substitute for a subroutine. Just as "set" is a poor man's substitute for an array. Why anyone would want to program in a language that only has one array, and that you can only index the first 9 elements of... Of course, I never write any sh programs... :-) Larry