Asked  10 Months ago    Answers:  5   Viewed   5 times

Is Perl compiled or interpreted?

 Answers

4

Well, that depends on what you mean by a compiled language. Maybe this is why googling did not bring forth a clear answer to your question.

One viewpoint is that compilation means compiling from a source code description to another, i.e. code generation.

If we accept these premises, then Perl 6 can be compiled and Perl 5 and older are interpreted languages.

Perl 6 is specifically compiled to Parrot bytecode. Perl 6 is therefore a properly compiled language, in the same way say, Java is.

Perl 5 and older parses the Perl source code to an internal list or tree, but I don't think it should be called a proper compiler, except maybe in a theoretical sense. It does not output any bytecode, assembly or real machine code usually associated with compilers. The parsing stage of Perl to check Perl syntax used to be called "compiling" the source. It is used to check the syntactical validity of a Perl source file without running it.

It is invoked as:

perl -c myprog.pl

But if you look at the help for Perl options, -c actually stands for "check".

-c                check syntax only (runs BEGIN and CHECK blocks)

(To further complicate things, Perl 5 had support for writing out internal bytecode but it was removed in version 5.10. Presumably because it was buggy, I don't know.)

On the other hand, if you argue that compilation is the act of parsing a source tree into any other kind of representation, well, that parsing makes Perl a compiled language. Perl must completely parse a source file before it can start executing it. By this definition, any language which can start executing a source file immediately before parsing would be an interpreted language.

A third way to look at this is from how these words, "interpreted" and "compiled" are most often used by professionals in the field. I would bet good money that if a random subset of programmers were asked to choose "compiled" or "interpreted" when thinking of Perl, most would choose "interpreted". Not because of some theoretical argument over the nature of Perl, but because "compiled" usually invokes thoughts of "compiling", "linking", "object code" etc, while "interpreted" is taken to mean "write the code, try it". Right or wrong, that may be good to know when trying to determine if Perl is, truly, interpreted or in fact, compiled. You are going to run into many arguments on your quest.

Sunday, August 8, 2021
2

What you can do is what multiple heavy-traffic websites do (like Facebook or Twitter), aka write your "CPU consuming" algorythm in a C-plugin.

For example, you could write a PHP extension if you plan to use PHP, or a Ruby extension if you plan to use Ruby / Ruby on Rails, etc.

That way, you can keep your streamline code simple and easy to maintain (it might be way harder to handle request from C rather than from PHP), while having a strong and solid background core (because it's compiled, and the compiler tells you what the issues are at compile time)

Saturday, May 29, 2021
 
Dev
 
Dev
1

Go and read the answers to this question

https://softwareengineering.stackexchange.com/questions/138521/is-javascript-interpreted-by-design

The answer I accepted is excellent and should help answer your question.

For me personally, I am somewhat cautious of the idea of calling a language interpreted or compiled. It's an implementation decision, not part of the language specification. If you want to talk about compiled or interpreted JavaScript, ask it in the context of an actual implementation of the language specification.

Tuesday, July 27, 2021
 
conmen
 
2

C# is compiled into IL, by the c# compiler.

This IL is then compiled just-in-time (JIT) as it's needed, into the native assembly language of the host machine. It would be possible to write a .NET runtime that interpreted the IL instead though. Even if this was done, I'd still argue that c# is a compiled language.

Tuesday, July 27, 2021
 
Daveel
 
1

I believe Lisp fits that description.

http://en.wikipedia.org/wiki/Common_Lisp

Thursday, September 9, 2021
 
Sasha
 
Only authorized users can answer the question. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :  
Share