Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: How is a perl program processed ?

by robartes (Priest)
on Apr 01, 2003 at 06:38 UTC ( [id://247159]=note: print w/replies, xml ) Need Help??


in reply to How is a perl program processed ?

Perl is somewhat of a hybrid between interpreted and compiled languages. There is indeed an interpreter that interprets the scripts, but it does not execute the interpreted code directly. Rather, it builds bytecode that in it's turn gets executed. The generation of the bytecode can be seen as a compilation step.

If you're interested, you can have a look at the bytecode of a script using the B::Bytecode module. For example:

$ perl -MO=Bytecode -e '$camel="flea-ridden";print $camel;' >bytecode
The file bytecode contains the bytecode.

In Perl6, this will be taken to the next step, and there will be a bytecode interpreter that's seperate from the Perl interpreter. This is parrot.

Update: As diotalevi rightly (if rather succinctly ;) ) points out, there is no bytecode. In fact, what I mistakingly and confusingly call bytecode, is in fact a serialisation of the internal optree the Perl interpreter generates. So, substitute 'optree' for 'bytecode' in the above, and you get an equally confusing, yet more correct explanation.

CU
Robartes-

Replies are listed 'Best First'.
Re: Re: How is a perl program processed ?
by diotalevi (Canon) on Apr 01, 2003 at 10:27 UTC

      Note that a Perl regex is compiled into a tree of regnodes while the rest of the Perl code is compiled into a tree of opcodes.

      So there are two different kinds of non-"byte-code"s here. The original inspiration of this thread was talking about regnodes while you've linked to a discussion about Perl opcodes.

      The regnodes and opcodes are quite similar, so the impressions people have gotten from this minor misdirection are likely rather accurate. (:

      I've heard that Perl is relatively slow at dispatching opcodes and relatively fast at dispatching regnodes such that formulating problems as a regex can be quite a bit faster than formulating them as Perl code. Not that this is usually an easy proposition.

                      - tye

        Great to see the topics diverting back to regex...i've been love with the beauty of regexes in perl. Wonder if there is any other language that has this capability of handling regex ?

        So why shud perl slow down while processing tree of opcodes if processing a tree of regnodes CAN be done faster ?

        If there is some optimized way of processing one kinda tree, cudnt it be applied to all nodetrees and make everything one step faster ?

        That cud make working with perl even more delightful!! I'm sure the monks cud throw some light in this angle i'm thinkin..

      That was really enlightening !!

      Thanks for all the info on perl being interpreted or compiled, but this last link proved to be the "missing link" in our discussions...i was actually searching for places to see how we can so freely use the term "bytecode" as in languages like java...this link provided the answer

      Got a good insight...and hope the discussion will be useful for other seekers!

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others perusing the Monastery: (7)
As of 2024-04-19 17:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found