The Perl Compiler

A native-code compiler for Perl is now (as of Perl 5.005) part of the standard Perl distribution. The compiler allows you to distribute Perl programs in binary form, which enables easy packaging of Perl-based programs without having to depend on the source machine having the correct version of Perl and the correct modules installed. After the initial compilation, running a compiled program should be faster to the extent that 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 byte code.

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 that lets you run the code you’ve generated with ...

Get Perl in a Nutshell 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.