next up previous contents
Next: The strict Pragma Up: Perl Modules Previous: The use Compiler Directive

Pragma in Perl

In a,hopefully futile, effort to confuse programmers, the use directive, was given a second job to do. It turns other compiler directives on and off. For example, you might want to force Perl to use integer math instead of floating-point match to speed up certain sections of your program.

Remember all of the new terminology that was developed for objects? The computer scientists have also developed their own term for a compiler directive. And that term is Pragma. The use statement controls the other pragmas.

The listing below shows a program that uses the integer pragma integer.pl:

print("Floating point math: ", 10 / 3, "\n");

use integer;

print("Integer math:        " 10 / 3, "\n");

This program displays:

Floating point math: 3.33333333333333
Integer math:        3

Pragmas can be turned off using the no compiler directive. For example, the following statement turns off the integer pragma:

no integer;

Here is a list of the pragmas that you can use.

integer
-- Forces integer math instead of floating point or double precision math.
less
-- Requests less of something,like memory or cpu time,from the compiler. This pragma has not been implemented yet.
sigtrap
-- Enables stack backtracing on unexpected signals.
strict
-- Restricts unsafe constructs. This pragma is highly recommended! Every program should use it. See next section.
subs
-- Lets you predeclare function names.

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