Interesting pronunciation. I wish you'd been there. Please note that there is no shewa between d and b. It sounds like I wish you(d) been there.
Live On Hope
Boring life. Despair in humanity, etc.
Monday, July 28, 2003
Wednesday, July 09, 2003
Friday, July 04, 2003
Exploring the Internals of Perl
Until recently, I had always thought that Perl is yet another a slow scripting language with an unstable, black box interpreter, which interprets the language in whatever way it likes. Now, I still think that Perl is a slow scripting langauge with an unstable interpreter, but a large part of Perl is no longer a black box to me, after I found ways to poke into the internals of Perl. With these techniques, I can udnerstand how exactly the interpreter sees my script, and can pretty much predict what is likely the results.
Believe it or not, one does not need to understand any Perl internals to figure out the most part of how Perl sees his script, thanks to the B::Deparse module. When Perl sees your script, it first compiles it to bytecode, and then the B::Deparse module will deparse the bytecode back into Perl. The result reveals an awful lot of information of the internal workings of the interpreter.
A more hard-core way to understand the internal workings is through the B::Concise module. Instead of translating the bytecodes back to Perl script, it prints them out in a human-readable fashion. There are over two hundred bytecodes. Each of them represents a basic operation. One will need to understand how Perl executes the bytecodes for the output to make sense.
The B modile is another very interesting module. The B represents "backend," which means that it can access Perl's compiled bytecode. The B::Concise and B::Deparse module mentioned earlier are two front-end modules built on top of B that translates the bytecode into different forms. With the B module, it is possible to write interesting language tools.
While it is important to know how Perl sees your script, it is also important to know how Perl represents its data structures internally.
It is also interesting to understand the interface between Perl and C. Not only does it helps you to write code to call Perl in C, and call C in Perl, since Perl also uses the same protocol internally to call Perl in Perl, understanding it helps one to have a sense of how parameters are passed and returned, and more important, the cost of doing it.
