Re: Compiling Perl to Bytecode (Was: Fruit basket program in Boo)

  • From: Veli-Pekka Tätilä <vtatila@xxxxxxxxxxxxxxxxxxxx>
  • To: programmingblind@xxxxxxxxxxxxx
  • Date: Mon, 22 Oct 2007 20:37:28 +0300

Hi Octavian.
Actually, Perl can compile to byte code it is just that not many people
know it.

perldoc B::Bytecode


    Compiles a Perl script into a bytecode format that could be loaded
    by the ByteLoader module and executed as a regular Perl script.

See the rest of the manual page for an example and some switches.


perldoc -f require hints: 

            <snip> Before "require" looks
            for a ".pm" extension, it will first look for a filename
with a
            ".pmc" extension. A file with this extension is assumed to
            Perl bytecode generated by B::Bytecode. If this file is
            and its modification time is newer than a coinciding ".pm"
            non-compiled file, it will be loaded in place of that
            non-compiled file ending in a ".pm" extension.
This applies to use as well:

perldoc -f use 

            It is exactly equivalent to
                BEGIN { require Module; import Module LIST; }
            except that Module *must* be a bareword.

I'm sure you'll be able to find some examples on the inet, too. The
bytecode support is still a bit experimental and there are certain
special cases and switches you should read about in the B::Bytecode man
page. Note that the 

perl -MO 

syntax means loads a special module called O which loads the Perl
compiler backends under the B::namespace. YOu can even disassemble Perl
code annd often the B::Deparse module is a great help in interpreting
how Perl actually executed your expression. See its man page, too.

With kind regards Veli-Pekka Tätilä (vtatila@xxxxxxxxxxxxxxxxxxxx)
Accessibility, game music, synthesizers and programming:

Octavian Rasnita wrote:
> If perl would be able to byte-compile the code and if there would be a
> friendly GUI library which is accessible and supports UTF-8, (and not a bad
> programming interface library like WX), I would be using only perl, because
> it has very many advantages in the other fields, and it is very productive.
View the list's information and change your settings at 

Other related posts: