next up previous contents
Next: The use Compiler Directive Up: Perl Modules Previous: Symbol Tables

The require Compiler Directive

The require directive is used to load Perl libraries. If you needed to load a library called Room.pl, you would do so like this:

require Room.pl;

No exporting of symbols is done by the require directive. So all symbols in the libraries must be explicitly placed into the main namespace. For example, you might see a library that looks like this:

package abbrev;


sub main'abbrev {

    # code for the function

}

Two things in this code snippet point out that it is Perl 4 code. The first is that the package name is in all lowercase. And the second is that a single quote is used instead of double colons to indicate a qualifying package name. Even though the abbrev() function is defined inside the abbrev package, it is not part of the %abbrev:: namespace because of the main' in front of the function name.

The require directive can also indicate that your script needs a certain version of Perl to run. For example, if you are using references, you should place the following statement at the top of your script: require 5.000;

And if you are using a feature that is available only with Perl 5.002-like prototypes-use the following:

require 5.002;

Perl 4 will generate a fatal error if these lines are seen.

Note Prototypes are not covered in this course. If you are using Perl 5.002 or later, prototypes should be discussed in the documentation that comes with the Perl distribution.


next up previous contents
Next: The use Compiler Directive Up: Perl Modules Previous: Symbol Tables
dave@cs.cf.ac.uk