Not "sub END {}" END { } This is the "END block", not a subroutine, and is special in that it is a "destructor" it will be executed as late a possible (that is, when Perl is exiting.) You can have a BEGIN {} block, that will execute when it is found as the script is compiling, as well. See the section on "Package Constructors and Destructors" in the perlmod man page (or under Go->Advanced Topics->Modules menus in Shuck.) Henry Penninkilampi wrote: > > Thanks to Chris and Joseph for responding so quickly with the END { } > suggestion. Seems to be just what I'm looking for. Problem is that it > doesn't seem to want to work! :( > > Simple example: > > --- > #!perl -w > > sub END > { > open LOG, ">>LOG.TXT"; > print LOG "END executed!\n"; > close LOG; > } > > print "Enter a command: "; > $command = <STDIN>; > print $command; > --- > > Now, if you run the above script (or save it as a runtime application and > run that) and then do a Command-Q on it *instead* of typing a command, > you'll probably get the following flash across your screen: > > # Callback called exit. > # END failed--cleanup aborted. > > (You might need to redirect STDERR to a file if you're on a fast machine.) > > NOTHING gets written to the log file. > > The behaviour I am looking for is that if the script/application is > prematurely terminated by the user (or the system), then the line "END > executed" is appended to the log file. > > What am I missing? > > Henry. > > # ===== Want to unsubscribe from this list? > # ===== Send mail with body "unsubscribe" to macperl-request@macperl.org # ===== Want to unsubscribe from this list? # ===== Send mail with body "unsubscribe" to macperl-request@macperl.org