aantonyselvam has asked for the wisdom of the Perl Monks concerning the following question:
Perl is an interpreted language, When I'm running my script, when is the compile time, and run time?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Compilation vs Interpretation
by moritz (Cardinal) on Feb 08, 2011 at 09:02 UTC | |
Most "compiled" languages like C and Fortran generate a binary code, which is then mapped by the CPU to more low-level instructions - it's actually interpreted by the CPU. "interpreted" lanuages like Perl are compiled to some intermediate code, and then executed on the fly. In the case of Perl the intermediate code is an in-memory optree. Then again other languages like Java have an explicit compilation step into a binary code, which can be run or JIT-compiled by a virtual machine. My point is that all modern programming system use both compilation and interpretation, depending on the level you're looking at it. | [reply] |
|
Re: Compilation vs Interpretation
by JavaFan (Canon) on Feb 08, 2011 at 12:54 UTC | |
When I'm running my script, when is the compile time, and run time?Compile time is first, run time is last*. In between, it switches. In fact, it switches from compile time to run time after it finished compiling a "unit" (file, BEGIN block, eval string). It switches to from run time to compile time when encountering something that needs compiling (require (if not already compiled), do, eval string, s///e), or, after running a compiled unit, there's more to compile. Perl is an interpreted languageMaybe, depending on your definition of "interpreted". It's not interpreted in the sense a shell script is. It is interpreted if one considers anything that separates compiling into a different process to be interpreted.
1Ok, when there's a syntax error, compile time may be the last step.2 | [reply] [d/l] [select] |
|
Re: Compilation vs Interpretation
by Anonymous Monk on Feb 08, 2011 at 07:41 UTC | |
Where did you hear that? When I'm running my script, when is the compile time, and run time? Where did you those terms? ?node_id=3989;HIT=compile%20time;re=N
Found 32 nodes roughly between 2011-02-08 and 1999-10-04 (searched 100.00% of DB). where title contains all of "compile", "time" | [reply] |
|
Re: Compilation vs Interpretation
by locked_user sundialsvc4 (Abbot) on Feb 08, 2011 at 15:18 UTC | |
When you present your Perl source-code, the first thing that happens is that it is translated into an intermediate form ... basically, a data-structure. A very similar thing happens, sometimes on-the-fly, when you use a regular expression. This is the phase called “compile time,” and indeed it is, even though the result is not “stand-alone executable machine instructions.” Then, as your program runs, what’s actually happening is that highly optimized code within “Perl itself” is iterating over that data-structure and doing what it says to do. This is “run time.” It used to be the case that compilers always generated pure machine-code output, and of course “C” compilers (and so forth) still can, but at the time when this was the de facto choice, machines were much smaller and slower and simply did not give you as many feasible choices to work with. (This approach also limits what the resulting programs can do.) It can now be shown that Perl’s “hybrid” approach is consistently faster, and certainly much more compact, in many real-world situations. The flexibility that it gives by “blurring the once-bright line” between compile-time and run-time is compelling, too. Almost every language tool today is implemented in this way. | |