Chapter 20. Perl Internals

It cannot be seen, cannot be felt, Cannot be heard, cannot be smelt. It lies behind stars and under hills, And empty holes it fills.[67]

J.R.R. Tolkien, The Hobbit

This chapter is a modest attempt to shed light on most of the critical data structures and functions of the Perl interpreter. Getting a handle on such (admittedly dry) detail will give you the confidence to write powerful extensions, and will inform your judgment about how (and how much) Perl should be used in a given application. The mark of a good Perl programmer is the ability to answer questions that don’t figure in the Frequently Asked Questions list, such as these:

  • Why are objects so much preferable to closures?

  • Why is my faster than local?

  • The easy-embedding API presented in the last chapter isn’t convenient enough. How can I roll my own?

  • What do xsubpp and SWIG really produce?

  • Why not join the Java revolution by making the Perl interpreter output Java byte-code?

And so on. All you require is fluency in C, an enquiring mind, and a comfortable chair.

If you are into instant gratification and can’t wait to churn out a cool extension, you may opt for the low-fat thread running through this chapter; read the following sections: Section 20.3, Section 20.4, and Section 20.5. You can definitely skip all sections entitled “Inside...” on a first reading without loss of continuity.

Reading the Source

There was this programmer, the story goes, who was deeply mystified by a piece of code. It had no comments ...

Get Advanced Perl Programming now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.