prad_intel has asked for the wisdom of the Perl Monks concerning the following question:

Hi All,

I am interested to know -

1) What actually happens when I convert my perl code to exe or How does perl get converted to an exe ?.

2) When I execute that exe , what are the internal operations that take place in a PC.

Thanks and Regards

Pradeep Soundararajan

Update : I am aware of PAR and per2exe but more interested at the internals of how does execution take place.

Updated after first reply

Replies are listed 'Best First'.
Re: perl exe execution
by superfrink (Curate) on Feb 24, 2006 at 05:48 UTC
    The pp tool in PAR is able to package a perl script (and modules) into an executable file. (EXE on Windows platforms.)

    I *believe* (but may be wrong) that basically the perl script is bundled together with a copy of the perl interpreter in one EXE file. There is an option to compile the code to bytecode.

    There is also a program called perlcc. This program compiles the perl code into an actual executable file. Note that perlcc has been considered beta for quite a while and not all perl code compiles nicely.

    There is a commercial program called perl2exe. I do not know much about it. I have never used it.

    Compiling perl code is asked about enough to get a FAQ entry, How can I compile my Perl program into byte code or C?.

    There is an old thread about compiling perl at Why has perl never been a compiled language....
Re: perl exe execution
by jonadab (Parson) on Feb 24, 2006 at 13:44 UTC
    1) What actually happens when I convert my perl code to exe or How does perl get converted to an exe ?.

    The way you ask this, it almost sounds as if you don't realize that Perl code *normally* is not converted to an exe. Perl code is, under ordinary circumstances, compiled very rapidly at execution time, by perl. This occasionally surprises people coming from other languages, like C, which require compilation and linking before execution, and which take a long time to do the compilation and linking. perl does it *very* quickly.

    superfrink has listed a number of ways to mimic more traditional compilation, but fundamentally Perl is not designed to work like that. Usually you just do something like perl my_perl_code.pl to execute your code, and perl reads your code and runs it on the spot, just like that, without any need for separate compilation and linking steps. This approach has a number of advantages, which we can discuss if you're interested.

    The cheif disadvantage is that when you distribute your code, you need perl itself also to be installed on all the systems that are going to run it. PAR and similar solutions are designed to work around that, but these days perl is included out of the box on almost every major operating system -- *every* major server-oriented operating system -- so it's becomming almost a non-issue except for desktop stuff. Desktop stuff of course usually needs to work in Windows, which still doesn't come with perl, although everything else has come with it for ten years or so. For Windows systems you still have to download and install perl, unless you use PAR or something like that.


    Sanity? Oh, yeah, I've got all kinds of sanity. In fact, I've developed whole new kinds of sanity. Why, I've got so much sanity it's driving me crazy.