Home: Perl Programming Help: Beginner:
perl interpreter

New User

Sep 22, 2012, 7:33 AM

Views: 1949
perl interpreter

I want to know if perl is implemented using interpreter or a compiler?
My guess is interpreter.Please confirm or rectify!

Chris Charley

Sep 22, 2012, 8:31 AM

Views: 1947
Re: [divineshiva] perl interpreter


Veteran / Moderator

Sep 23, 2012, 8:37 PM

Views: 1934
Re: [Chris Charley] perl interpreter

The short answer is that a Perl script is definitely compiled before anything happens. If compilation fails, the program will not run. In purely interpreted languages, the program could possiblty run for a while before a syntax error is found and stops execution. In Perl, this is not so, the entire source code is compiled before execution starts. If an error is found, the execution will not start, which sort of proofs that this is really a compilation phase.

But a Perl script is not compiled into binary code directly understandable by the processor, as is the case for C or C++ code, for example (I am simplifying, but that's the idea). This has some advantages (portability) and some drawbacks (more limited performance, in some cases only).

A perl scrip is compiled into what could be called byte codes or operation codes, that are then ran by the perl interpreter, somewhat similarly to what happens with Java code and the Java virtual machine.

(OK, this is simplification, the comparison between Java and Perl does make senses, but, then, there are some significant différences).