The Perl Compiler

Starting with Perl 5.005, the Perl compiler became part of the standard Perl distribution. You’ll find that with Perl 5.6 and later, the Perl compiler has become far more stable. The compiler allows you to distribute Perl programs in binary form, which enables easy packaging of Perl-based programs without relying on the source machine to have the correct version of Perl and the correct modules installed. After the initial compilation, running a compiled program should be faster because it doesn’t have to be recompiled each time it’s run. However, you shouldn’t expect that the compiled code itself will run faster than the original Perl source or that the executable will be smaller—in reality, the executable file is likely to be significantly bigger.

This initial release of the compiler is still considered to be a beta version. It’s distributed as an extension module, B, that comes with the following backends:

Bytecode

Translates a script into platform-independent Perl bytecode.

C

Translates a Perl script into C code.

CC

Translates a Perl script into optimized C code.

Deparse

Regenerates Perl source code from a compiled program.

Lint

Extends the Perl -w option. Named after the Unix Lint program-checker.

Showlex

Shows lexical variables used in functions or files.

Xref

Creates a cross-reference listing for a program.

Once you’ve generated the C code with either the C or the CC backend, you run the cc_harness program to compile it into an executable. There is also a byteperl interpreter ...

Get Perl in a Nutshell, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.