next up previous contents
Next: Symbol Tables Up: Module Constructors and Destructors Previous: The BEGIN Block

The END Block

The END blocks are the last thing to be evaluated. They are even evaluated after exit() or die() functions are called. Therefore, they can be used to close files or write messages to log files. Multiple END blocks are evaluated in reverse order.

END {

    print("main\n");

}



package Foo;

    END {

        print("Foo\n");

    }

This program displays:

Foo
Main

Note Signals that are sent to your script can bypass the END blocks. So, if your script is in danger of stopping due to a signal, be sure to define a signal-handler function. See Chapter 13, "Handling Errors and Signals," for more information.



dave@cs.cf.ac.uk