Beefy Boxes and Bandwidth Generously Provided by pair Networks RobOMonk
more useful options
 
PerlMonks  

Are the scripts interpreted or compiled?

( #170664=categorized question: print w/ replies, xml ) Need Help??
Contributed by jotti on May 31, 2002 at 10:41 UTC
Q&A  > CGI programming


Description:

What happens when my CGI Perl script is called? Is every line interpreted every time the program comes to the line? F.i. if I have the following lines:

for (i = 0; i < 100; i++) { print "Hello, World\n"; }
...will the print line be interpreted 100 times? (I believe this was the case in old great interpreters like GWBASIC and QBASIC.) Or is the whole script compiled once every time it is called and then run like a compiled C++ executable CGI "script"?

Answer: Are the scripts interpreted or compiled?
contributed by Elian

Much as I like perl, this first answer is incorrect.

Perl is certainly not the most perfect combination if interpreter and compiler. It's arguable whether there is one, but if there is then what we have now isn't it.

While, strictly speaking, perl does have a compilation phase, transforming your source into an intermediate internal representation, it doesn't produce natively executable code. Producing that native code is what's generally associated with compilation. Instead it produces the intermediate code and walks through it, interpreting it.

Given the current state of the art (at this point only a few shells are truly interpretive, not turning their code into some intermediate form) perl comfortably fits the definition of "interpreter"

(Also, perl doesn't produce and interpret bytecode. It produces and walks an optree, which is a different structure altogether)

Answer: Are the scripts interpreted or compiled?
contributed by Juerd

It is compiled on the fly. Perl is the most perfect combination of interpreter and compiler.

Your example script would be compiled to bytecode first, and the bytecode would be executed. The bytecode generated by the print statement is executed 100 times.

If you are concerned with efficiency, use for (1..100) instead of the C-style for.

Answer: Are the scripts interpreted or compiled?
contributed by Marza

Depending on the need and the platform. ActiveState has Perlapp which will turn your script into an executable.

Answer: Are the scripts interpreted or compiled?
contributed by Jenda

The fact that something is named *.exe doesn't mean it contains ONLY compiled code. The script is NOT really compiled by PerlApp. It's just packed up with some startup code, Perl interpreter, DLLs of the modules you need (if built as freestanding) and so forth. I do not think it's even compiled to bytecode before being stored in the EXE.

Please (register and) log in if you wish to add an answer



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • Outside of code tags, you may need to use entities for some characters:
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others pondering the Monastery: (12)
    As of 2014-04-23 17:32 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      April first is:







      Results (551 votes), past polls