next up previous contents
Next: The END Block Up: Module Constructors and Destructors Previous: Module Constructors and Destructors

The BEGIN Block

The BEGIN block is evaluated as soon as it is defined. Therefore, it can include other functions using do() or require statements. Since the blocks are evaluated immediately after definition, multiple BEGIN blocks will execute in the order that they appear in the script.

For Example (export.pl):

The Perl code is (export.pl):

BEGIN {

    print("main\n");

}



package Foo;

    BEGIN {

        print("Foo\n");

    }

This program displays:

main
Foo



dave@cs.cf.ac.uk