Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: Perl is a compiler cum interpreter?

by GrandFather (Saint)
on Feb 15, 2007 at 06:30 UTC ( #600144=note: print w/replies, xml ) Need Help??


in reply to Perl is a compiler cum interpreter?

A compiler runs over source code and generates output code without executing the output code. Generally the output winds up as native machine code that is subsequently executed in a different context.

An interpreter runs over source code and executes it as it goes (possibly compiling fragments into an intermediate representation).

Perl does both. It runs over the source code and compiles it into an intermediate form. It then "interprets" the intermediate form. Note that this gets somewhat more interesting when eval is involved because the code fragment passed into eval needs to be compiled and interpreted in its turn.

Update fix stupidty and add documentation links for eval


DWIM is Perl's answer to Gödel
  • Comment on Re: Perl is a compiler cum interpreter?

Replies are listed 'Best First'.
Re^2: Perl is a compiler cum interpreter?
by izut (Chaplain) on Feb 15, 2007 at 08:37 UTC
    Perl does both. It runs over the source code and compiles it into an intermediate form. It then "interprets" the intermediate form. Note that this gets somewhat more interesting when eval is involved because the code fragment passed into eval needs to be compiled and interpreted in its turn.

    From perldoc -f eval

    In the second form, the code within the BLOCK is parsed only once--at +the same time the code surrounding the "eval" itself was parsed--and execu +ted within the context of the current Perl program. This form is typicall +y used to trap exceptions more efficiently than the first (see below), while also providing the benefit of checking the code within BLOCK at compile time.

    P.S.: I'm posting this for those like I had somekind of doubt if eval BLOCK interprets and compiles the code inside BLOCK. The answer is no.

    Igor 'izut' Sutton
    your code, your rules.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://600144]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (3)
As of 2021-04-11 08:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?