Welcome to Linux Knowledge Base and Tutorial
"The place where you learn linux"

 Create an AccountHome | Submit News | Your Account  

Tutorial Menu
Linux Tutorial Home
Table of Contents

· Introduction to Operating Systems
· Linux Basics
· Working with the System
· Shells and Utilities
· Editing Files
· Basic Administration
· The Operating System
· The X Windowing System
· The Computer Itself
· Networking
· System Monitoring
· Solving Problems
· Security
· Installing and Upgrading
· Linux and Windows

Man Pages
Linux Topics
Test Your Knowledge

Site Menu
Site Map
Copyright Info
Terms of Use
Privacy Info
Masthead / Impressum
Your Account

Private Messages

News Archive
Submit News
User Articles
Web Links


The Web

Who's Online
There are currently, 71 guest(s) and 0 member(s) that are online.

You are an Anonymous user. You can register for free by clicking here




       Perl has always had a compiler: your source is compiled
       into an internal form (a parse tree) which is then opti­
       mized before being run.  Since version 5.005, Perl has
       shipped with a module capable of inspecting the optimized
       parse tree ("B"), and this has been used to write many
       useful utilities, including a module that lets you turn
       your Perl into C source code that can be compiled into a
       native executable.

       The "B" module provides access to the parse tree, and
       other modules ("back ends") do things with the tree.  Some
       write it out as bytecode, C source code, or a semi-human-
       readable text.  Another traverses the parse tree to build
       a cross-reference of which subroutines, formats, and vari­
       ables are used where.  Another checks your code for dubi­
       ous constructs.  Yet another back end dumps the parse tree
       back out as Perl source, acting as a source code beauti­
       fier or deobfuscator.

       Because its original purpose was to be a way to produce C
       code corresponding to a Perl program, and in turn a native
       executable, the "B" module and its associated back ends
       are known as "the compiler", even though they don't really
       compile anything.  Different parts of the compiler are
       more accurately a "translator", or an "inspector", but
       people want Perl to have a "compiler option" not an
       "inspector gadget".  What can you do?

       This document covers the use of the Perl compiler: which
       modules it comprises, how to use the most important of the
       back end modules, what problems there are, and how to work
       around them.


       The compiler back ends are in the "B::" hierarchy, and the
       front-end (the module that you, the user of the compiler,
       will sometimes interact with) is the O module.  Some back
       ends (e.g., "B::C") have programs (e.g., perlcc) to hide
       the modules' complexity.

       Here are the important back ends to know about, with their
       status expressed as a number from 0 (outline for later
       implementation) to 10 (if there's a bug in it, we're very

           Stores the parse tree in a machine-independent format,
           suitable for later reloading through the ByteLoader
           module.  Status: 5 (some things work, some things
           don't, some things are untested).
           reduce (given sufficient type information in the Perl
           program) some of the Perl data structure manipulations
           into manipulations of C-level ints, floats, etc.  Sta­
           tus: 5 (some things work, including uncomplicated Tk

           Complains if it finds dubious constructs in your
           source code.  Status: 6 (it works adequately, but only
           has a very limited number of areas that it checks).

           Recreates the Perl source, making an attempt to format
           it coherently.  Status: 8 (it works nicely, but a few
           obscure things are missing).

           Reports on the declaration and use of subroutines and
           variables.  Status: 8 (it works nicely, but still has
           a few lingering bugs).

Using The Back Ends

       The following sections describe how to use the various
       compiler back ends.  They're presented roughly in order of
       maturity, so that the most stable and proven back ends are
       described first, and the most experimental and incomplete
       back ends are described last.

       The O module automatically enabled the -c flag to Perl,
       which prevents Perl from executing your code once it has
       been compiled.  This is why all the back ends print:

         myperlprogram syntax OK

       before producing any other output.

       The Cross Referencing Back End

       The cross referencing back end (B::Xref) produces a report
       on your program, breaking down declarations and uses of
       subroutines and variables (and formats) by file and sub­
       routine.  For instance, here's part of the report from the
       pod2man program that comes with Perl:

         Subroutine clear_noremap
           Package (lexical)
             $ready_to_print   i1069, 1079
           Package main
             $&                1086
             $.                1086
             $0                1086
             $1                1087

           the first time.

       &   Subroutine or method call.

       s   Subroutine defined.

       r   Format defined.

       The most useful option the cross referencer has is to save
       the report to a separate file.  For instance, to save the
       report on myperlprogram to the file report:

         $ perl -MO=Xref,-oreport myperlprogram

       The Decompiling Back End

       The Deparse back end turns your Perl source back into Perl
       source.  It can reformat along the way, making it useful
       as a de-obfuscator.  The most basic way to use it is:

         $ perl -MO=Deparse myperlprogram

       You'll notice immediately that Perl has no idea of how to
       paragraph your code.  You'll have to separate chunks of
       code from each other with newlines by hand.  However,
       watch what it will do with one-liners:

         $ perl -MO=Deparse -e '$op=shift||die "usage: $0
         code [...]";chomp(@ARGV=<>)unless@ARGV; for(@ARGV){$was=$_;eval$op;
         die$@ if$@; rename$was,$_ unless$was eq $_}'
         -e syntax OK
         $op = shift @ARGV || die("usage: $0 code [...]");
         chomp(@ARGV = <ARGV>) unless @ARGV;
         foreach $_ (@ARGV) {
             $was = $_;
             eval $op;
             die $@ if $@;
             rename $was, $_ unless $was eq $_;

       The decompiler has several options for the code it gener­
       ates.  For instance, you can set the size of each indent
       from 4 (as above) to 2 with:

         $ perl -MO=Deparse,-si2 myperlprogram

       The -p option adds parentheses where normally they are

         $ perl -MO=Deparse -e 'print "Hello, world\n"'
         -e syntax OK
         print "Hello, world\n";

       To run the style checker across your source code:

         $ perl -MO=Lint myperlprogram

       To disable context checks and undefined subroutines:

         $ perl -MO=Lint,-context,-undefined-subs myperlprogram

       See B::Lint for information on the options.

       The Simple C Back End

       This module saves the internal compiled state of your Perl
       program to a C source file, which can be turned into a
       native executable for that particular platform using a C
       compiler.  The resulting program links against the Perl
       interpreter library, so it will not save you disk space
       (unless you build Perl with a shared library) or program
       size.  It may, however, save you startup time.

       The "perlcc" tool generates such executables by default.

         perlcc myperlprogram.pl

       The Bytecode Back End

       This back end is only useful if you also have a way to
       load and execute the bytecode that it produces.  The
       ByteLoader module provides this functionality.

       To turn a Perl program into executable byte code, you can
       use "perlcc" with the "-B" switch:

         perlcc -B myperlprogram.pl

       The byte code is machine independent, so once you have a
       compiled module or program, it is as portable as Perl
       source (assuming that the user of the module or program
       has a modern-enough Perl interpreter to decode the byte

       See B::Bytecode for information on options to control the
       optimization and nature of the code generated by the Byte­
       code module.

       The Optimized C Back End

       The optimized C back end will turn your Perl program's run
       time code-path into an equivalent (but optimized) C pro­
       gram that manipulates the Perl data structures directly.
       The program will still link against the Perl interpreter

Module List for the Compiler Suite

       B   This module is the introspective ("reflective" in Java
           terms) module, which allows a Perl program to inspect
           its innards.  The back end modules all use this module
           to gain access to the compiled parse tree.  You, the
           user of a back end module, will not need to interact
           with B.

       O   This module is the front-end to the compiler's back
           ends.  Normally called something like this:

             $ perl -MO=Deparse myperlprogram

           This is like saying "use O 'Deparse'" in your Perl

           This module is used by the B::Assembler module, which
           is in turn used by the B::Bytecode module, which
           stores a parse-tree as bytecode for later loading.
           It's not a back end itself, but rather a component of
           a back end.

           This module turns a parse-tree into data suitable for
           storing and later decoding back into a parse-tree.
           It's not a back end itself, but rather a component of
           a back end.  It's used by the assemble program that
           produces bytecode.

           This module is used by the B::CC back end.  It walks
           "basic blocks".  A basic block is a series of opera­
           tions which is known to execute from start to finish,
           with no possibility of branching or halting.

           This module is a back end that generates bytecode from
           a program's parse tree.  This bytecode is written to a
           file, from where it can later be reconstructed back
           into a parse tree.  The goal is to do the expensive
           program compilation once, save the interpreter's state
           into a file, and then restore the state from the file
           when the program is to be executed.  See "The Bytecode
           Back End" for details about usage.

           This module writes out C code corresponding to the
           parse tree and other interpreter internal structures.
           You compile the corresponding C file, and get an exe­
           cutable file that will restore the internal structures

           This module prints a concise (but complete) version of
           the Perl parse tree.  Its output is more customizable
           than the one of B::Terse or B::Debug (and it can emu­
           late them). This module useful for people who are
           writing their own back end, or who are learning about
           the Perl internals.  It's not useful to the average

           This module dumps the Perl parse tree in verbose
           detail to STDOUT.  It's useful for people who are
           writing their own back end, or who are learning about
           the Perl internals.  It's not useful to the average

           This module produces Perl source code from the com­
           piled parse tree.  It is useful in debugging and
           deconstructing other people's code, also as a pretty-
           printer for your own source.  See "The Decompiling
           Back End" for details about usage.

           This module turns bytecode back into a parse tree.
           It's not a back end itself, but rather a component of
           a back end.  It's used by the disassemble program that
           comes with the bytecode.

           This module inspects the compiled form of your source
           code for things which, while some people frown on
           them, aren't necessarily bad enough to justify a warn­
           ing.  For instance, use of an array in scalar context
           without explicitly saying "scalar(@array)" is some­
           thing that Lint can identify.  See "The Lint Back End"
           for details about usage.

           This module prints out the my() variables used in a
           function or a file.  To get a list of the my() vari­
           ables used in the subroutine mysub() defined in the
           file myperlprogram:

             $ perl -MO=Showlex,mysub myperlprogram

           To get a list of the my() variables used in the file

             $ perl -MO=Showlex myperlprogram

           This module prints the contents of the parse tree, but
           without as much information as B::Debug.  For compari­
           son, "print "Hello, world.""  produced 96 lines of
           output from B::Debug, but only 6 from B::Terse.

           This module is useful for people who are writing their
           own back end, or who are learning about the Perl
           internals.  It's not useful to the average programmer.

           This module prints a report on where the variables,
           subroutines, and formats are defined and used within a
           program and the modules it loads.  See "The Cross Ref­
           erencing Back End" for details about usage.


       The simple C backend currently only saves typeglobs with
       alphanumeric names.

       The optimized C backend outputs code for more modules than
       it should (e.g., DirHandle).  It also has little hope of
       properly handling "goto LABEL" outside the running subrou­
       tine ("goto &sub" is okay).  "goto LABEL" currently does
       not work at all in this backend.  It also creates a huge
       initialization function that gives C compilers headaches.
       Splitting the initialization function gives better
       results.  Other problems include: unsigned math does not
       work correctly; some opcodes are handled incorrectly by
       default opcode handling mechanism.

       BEGIN{} blocks are executed while compiling your code.
       Any external state that is initialized in BEGIN{}, such as
       opening files, initiating database connections etc., do
       not behave properly.  To work around this, Perl has an
       INIT{} block that corresponds to code being executed
       before your program begins running but after your program
       has finished being compiled.  Execution order: BEGIN{},
       (possible save of state through compiler back-end),
       INIT{}, program runs, END{}.


       This document was originally written by Nathan Torkington,
       and is now maintained by the perl5-porters mailing list

perl v5.8.1                 2003-09-02             PERLCOMPILE(1)

An undefined database error occurred. SELECT distinct pages.pagepath,pages.pageid FROM pages, page2command WHERE pages.pageid = page2command.pageid AND commandid =

Help us cut cost by not downloading the whole site!
Use of automated download sofware ("harvesters") such as wget, httrack, etc. causes the site to quickly exceed its bandwidth limitation and therefore is expressedly prohibited. For more details on this, take a look here



Security Code
Security Code
Type Security Code

Don't have an account yet? You can create one. As a registered user you have some advantages like theme manager, comments configuration and post comments with your name.

Help if you can!

Amazon Wish List

Did You Know?
You can get all the latest Site and Linux news by checking out our news page.


Tell a Friend About Us

Bookmark and Share

Web site powered by PHP-Nuke

Is this information useful? At the very least you can help by spreading the word to your favorite newsgroups, mailing lists and forums.
All logos and trademarks in this site are property of their respective owner. The comments are property of their posters. Articles are the property of their respective owners. Unless otherwise stated in the body of the article, article content (C) 1994-2013 by James Mohr. All rights reserved. The stylized page/paper, as well as the terms "The Linux Tutorial", "The Linux Server Tutorial", "The Linux Knowledge Base and Tutorial" and "The place where you learn Linux" are service marks of James Mohr. All rights reserved.
The Linux Knowledge Base and Tutorial may contain links to sites on the Internet, which are owned and operated by third parties. The Linux Tutorial is not responsible for the content of any such third-party site. By viewing/utilizing this web site, you have agreed to our disclaimer, terms of use and privacy policy. Use of automated download software ("harvesters") such as wget, httrack, etc. causes the site to quickly exceed its bandwidth limitation and are therefore expressly prohibited. For more details on this, take a look here

PHP-Nuke Copyright © 2004 by Francisco Burzi. This is free software, and you may redistribute it under the GPL. PHP-Nuke comes with absolutely no warranty, for details, see the license.
Page Generation: 0.11 Seconds