home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #18 / NN_1992_18.iso / spool / comp / lang / perl / 5322 < prev    next >
Encoding:
Text File  |  1992-08-14  |  2.4 KB  |  45 lines

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