Is Perl a compiled or an interpreted programming language?

Mr. L picture Mr. L · Mar 21, 2011 · Viewed 27.4k times · Source

Is Perl compiled or interpreted?

Answer

tchrist picture tchrist · Mar 21, 2011

You aren’t going to get a definite answer, because you haven’t provided a definite question.

Perl is always in one of two states: it is either compiling, or it is executing. That’s why you see talk of “at compile-time” vs “at run-time”. Normally, you get one compile phrase followed by one execution phase, but it need not be that way.

These two phases can also trade back and forth. An eval STRING is a way for the interpreter to call the compiler (so too therefore are do FILE and require). A BEGIN block is a way for the compiler to call the interpreter (so too therefore are use and no).

When you run perl -c, you omit the run-time phase. There are various ways to skip the compile-time phase, but none of them is particularly convenient, or commonplace. Apache’s mod_perl only compiles scripts once but executes them many times. If you use the Byteloader, you can do the same. Et cetera.

The correct answer to whether Perl is compiled or interpreted is simply YES.