Re: How perl program execution happened ?



From: "Chas. Owens" <chas.owens@xxxxxxxxx>
On Fri, May 30, 2008 at 4:50 AM, sivasakthi <msivasakthi@xxxxxxxxx> wrote:
Hi all,

It is a very basic question. But i want clear idea about how the perl
program execution was happened. I know Perl is a Interpreter language.I
need more information about whats going there internally .

could you explain or direct me right document?
snip

Perl is not interpreted. This is a common misconception. A program
written in Perl is compiled into an optree in its first stage of
running. This optree is then executed by perl. The best place to go
looking is probably "Programming Perl" (aka the Camel). Is there
something specific you want to know, or are you just curious?

Well, first stage ... the stages of script compilation and execution
are intertwinned.

perl compiles the script, but as soon as it compiles a complete
BEGIN{} block or a use statement it stops compiling and executes that
block/statement. Which in case of use means that it evaluates the
parameters for the loaded module (the use Module::Name qw(thing
here)) and reads and starts compiling the module (handling BEGIN{}
blocks and use statements there). When it's finished compiling the
module it executes the code in side the module that's not inside any
subroutine and then calls the modules import() subroutine. Only after
that it switches back to the compilation stage and continues
compiling the main script. And I did not even mention END{}, CHECK{}
and INIT{} and I believe there are more.

This means that the used modules may affect even the way the rest of
the script is parsed. Or optimized. Eg. the module may compute some
constants and the optimizer may evaluate constant expressions, remove
unreachable parts of code etc. etc.

This causes problems on the other hand if you wanted to store the
optree in a file and then execute the file "directly" without perl
having to recompile all those source files. The catch (one of
several) is that before everything is fully compiled a lot of code
was actually executed. And it may very well have done something you
want to do every time the program runs and not when it's compiled
into an serialized optree file.

On the other hand the experiments in this area proved that any speed
improvements (that can anyway only affect the startup time, not the
"execution" itself) this may provide are so small that it's not worth
it. The case when the repeated compilation causes problems are better
solved by persistent solutions. That is instead of starting (and
compiling) the program (in this case usualy the "CGI" script) over
and over again, you start it once and let it serve many requests.
Using things like mod_perl, FastCGI, PerlEx, etc.

Jenda
===== Jenda@xxxxxxxxxxx === http://Jenda.Krynicky.cz =====
When it comes to wine, women and song, wizards are allowed
to get drunk and croon as much as they like.
-- Terry Pratchett in Sourcery

.



Relevant Pages

  • Re: preventing a user to start a process
    ... You can use some perl to split the lines to find out how long the processes ... >> located in file systems that allow execution. ... >> are running for a certain period of time and are not the apache. ... Does anyone know a usable script for that ...
    (freebsd-isp)
  • Re: get the result of calling another script
    ... > execution of script B is successful, can someone show me how to do that? ... I assume you mean Perl scripts. ... Or do you perhaps mean you want to execute additional Perl code (which ... you call "script B" from some other Perl code you call "script A", ...
    (comp.lang.perl.misc)
  • Re: Scripting help
    ... > I appreciate your quick response. ... > Is there any way I get the time taken for the execution of a script from ... > the script itself instead of typing it at the command line. ... I prefer to use Perl anyways, but I would've like to get this working ...
    (RedHat)
  • Re: compiling PERL programs
    ... I posed a question about compiling a while ago and got this ... To turn a Perl program into executable byte code, you can use 'perlcc' ... I saw this in the DOS window: ...
    (perl.beginners)
  • report (problems compiling DBD::Oracle on Solaris 10)
    ... As stated in the README file i'm reporting issues compiling DBD::Oracle ... Platform is Solaris 10 on Sun Fire T2000 ... (using 'perl Makeperl.PL -p' also fails) ...
    (perl.dbi.users)