home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.perl
- Path: sparky!uunet!usc!sol.ctr.columbia.edu!destroyer!ubc-cs!phillips
- From: phillips@cs.ubc.ca (George Phillips)
- Subject: Re: die hook
- Message-ID: <1992Aug27.052530.11544@cs.ubc.ca>
- Sender: usenet@cs.ubc.ca (Usenet News)
- Organization: Computer Science, University of B.C., Vancouver, B.C., Canada
- References: <Aug.13.17.56.21.1992.22441@piecomputer.rutgers.edu> <1992Aug15.030457.21382@netlabs.com>
- Date: Thu, 27 Aug 92 05:25:30 GMT
- Lines: 30
-
- In article <1992Aug15.030457.21382@netlabs.com> lwall@netlabs.com (Larry Wall) writes:
- >The code I'm developing for Perl 5 already has two magical subroutines
- >in it called BEGIN and END. They're so magical that you don't even have
- >to put "sub" in front of them. BEGIN is automatically called before
- >the program starts, and END is automatically called just before the
- >program exits, no matter how it exits.
-
- Do you get a magical BEGIN and END for each package or just one set for
- the entire program? Seems like it would be a great way for required
- subroutine modules to install cleanup routines without extra bookkeeping
- on the part of the main program. The BEGIN subroutine may be a problem
- since the earliest it could run would be at require time, but then
- again required files already have BEGIN.
-
- I guess you could make non-lazy programmers write out their ENDing
- sequence explicitly:
-
- END {
- &foo'END;
- &bar'END;
- print "Bye!\n";
- }
-
- But that means that some day you'll forget to add an END call when
- you do a require. I think it would be better to call each package's
- END in reverse order of initial definition of each package (which
- guarantees main'END would be last, right?). You might be upset
- that the main program cannot decide for itself if a module should
- be shut down, but it's only fair to assume that if a module needs
- to prepare for death it has good reasons for doing so.
-