From: "Chas. Owens" <[EMAIL PROTECTED]>
> On Fri, May 30, 2008 at 4:50 AM, sivasakthi <[EMAIL PROTECTED]> 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
===== [EMAIL PROTECTED] === 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


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to