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

Dear monks I'm puzzled.
I have begun learning Perl for a week now. What I have noticed is that the book often mentions instructions or code that will be effective at compilation time.

What is the "compilation time", I know perl is an interpreted language, so I guess there 'must' be an 'anti' for "compilation time" what is it?

And also why do we have to use eval for variable is the instruction will run at compilation time? thanks

Replies are listed 'Best First'.
Re: compilation time and what else?
by holli (Abbot) on Feb 27, 2005 at 14:19 UTC
    Yes, perl is an interpreter. But it does not work like the early interpreters did (read a line, interpret it, execute it, go on to the next line). What happens is, once you start the script, the code gets parsed and "compiled" into an internal parse tree, aka bytecode format.

    The "anti" is the "run time". That is when the Perl interpreter is executing the bytecode.

    Update:
    The article FMTEYEWTK about Compilation vs Interpretation in Perl provides more detail.


    holli, /regexed monk/
Re: compilation time and what else?
by punkish (Priest) on Feb 27, 2005 at 14:18 UTC
    What is the "compilation time", I know perl is an interpreted language, so I guess there 'must' be an 'anti' for "compilation time" what is it?
    Perl is an interpreted language in that you don't have to explicitly compile your program before running it, like you have to do in C. However, Perl is also a compiled language in that the Perl interpreter (compiler) automatically compiles your program into an intermediate code before it runs it. Hence, "compile time" and "run time."

    If there are any syntax errors in your code, compilation fails. If compilation succeeds, you may still have logical errors and your program may not do what you expected it to do. There are also things you can do that happen at compile time (for example, a BEGIN block) before the rest of the program actually runs.

    --
    when small people start casting long shadows, it is time to go to bed
Re: compilation time and what else?
by davido (Cardinal) on Feb 27, 2005 at 17:29 UTC

    eval (the quoted string version) basically gets the Perl interpreter to start up again on a new section of code, compiling it, intrepreting it, and executing it. I'm not sure what you mean by "...use eval for variable is the instruction will run at compilation time?" Perhaps you can rephrase that portion of the question if you're still unclear on the answer.


    Dave