home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.perl
- Path: sparky!uunet!ftpbox!mothost!merlin.dev.cdx.mot.com!merlin.dev.cdx.mot.com!lezz
- From: lezz@merlin.dev.cdx.mot.com (Lezz Giles)
- Subject: Re: die hook
- Message-ID: <1992Aug14.153525.18568@merlin.dev.cdx.mot.com>
- Sender: news@merlin.dev.cdx.mot.com (USENET News System)
- Nntp-Posting-Host: monarch.dev.cdx.mot.com
- Reply-To: lezz@merlin.dev.cdx.mot.com (Lezz Giles)
- Organization: Motorola Codex, Canton, MA
- References: <Aug.13.17.56.21.1992.22441@piecomputer.rutgers.edu>
- Date: Fri, 14 Aug 1992 15:35:25 GMT
- Lines: 31
-
- In article <Aug.13.17.56.21.1992.22441@piecomputer.rutgers.edu>, mende@piecomputer.rutgers.edu (Bob Mende Pie) writes:
- |> I am currently working on a set of programs that use common "required"
- |>packages. I use the die command in many of the different monules and
- |>packages. Depending on what main program I use to invoke the program, I
- |>would possibly like to add a "hook" to the die command that would run a
- |>subroutine before exiting. It could be used for cleaning up lockfiles,
- |>saving the state of arrays, whatever. Since I can not be sure how my
- |>modules will be called this hook may or not be in existance. Is there a
- |>subroutine that die will try to call when it is invoked. If not this
- |>would be a useful addition. It could be as simple as the perl code:
- |> &'die if defined &'die;
-
- I have a similar situation in one of my tools - I simply always have
- a subroutine (I call it &exit(), but it sounds like you should call
- yours &die()) which does everything I want when the program is about
- to finish. You could put this die subroutine in yet another module
- and have lots of 'require "die.pl";' statements scattered all over the
- place.
-
- As a side comment, it's interesting that as I get deeper and deeper into
- Perl I find that often the builtin functions don't quite do what I want (e.g.
- exit() doesn't tidy things up the way I want, system() doesn't handle
- signals and stdout/stderr the way I want, etc. etc.), but I also find
- that Perl is so flexible and powerful that I can almost always write
- replacements that will do precisely what I want. The only exceptions
- that I've found so far, where I've had to drop down to C code programs
- called via system(), are to find out the current action associated with
- a signal (why, in Grod's name, isn't %SIG initialized at the beginning?),
- and to find out full a filesystem is (which is probably pretty OS-dependent).
-
- Lezz "learning to be yaph...." Giles
-