Slashdot Mirror


Extending and Embedding Perl

ggoebel writes "Extending and Embedding Perl is, as it boldly states on the cover, 'The definitive guide to XS, embedding, and the Perl internals.' This book is well organized and information dense. One could spend days sifting through the available perlapi, perlcall, perlembed, perlguts perlxs, perlxstut, and h2xs documentation. After which you'll probably understand very well references to nethack's 'You are in a maze of twisty little passages all alike.' Or you could get yourself a copy of this book and find your way out of the maze." Read on for the rest of ggoebel's review. Extending and Embedding Perl author Tim Jenness and Simon Cozens pages 384 publisher Manning (August 2002) rating 9 of 10 reviewer ggoebel ISBN 1930110820 summary The definitive guide to XS, embedding, and the Perl internals

Most of the available documentation on extending and embedding perl is written from the prospective of the core perl developers for core perl developers. This book is written for advanced Perl programmers who for whatever reason need or wish to peer into that netherworld between Perl, C, and the glue that interfaces Perl with other languages. It is a deliberate thorough guide led by authors that are both extremely knowledgeable and also capable of communicating that knowledge.

While it would greatly reduce the learning curve, no prior knowledge of C is required to read this book. This is a surprising claim and while it won't be easy, this reader is proof that someone with little true knowledge of C can in fact read and for the most part comprehend what the authors wish to convey.

There are clearly areas for improvement. Things like NULL being used throughout chapter 3, only to finally be defined later in a footnote in chapter 4. And other cases of terms being used before they are explained. Things that leave the reader juggling unnecessarily until the information is provided that lets understanding fall into place. But for the most part, if you are a competent juggler and are patient your questions will eventually be answered. You won't walk away a C programmer, but you will learn enough to solve the problems which led you to consider reading this book in the first place.

One thing I liked very much about the layout of the book is how it switches back between presenting sections on C programming and Perl. The authors revisit C each time it is necessary to understand the next Perl internals topic. Those that are learning C or need the review receive the relevant information just before it is required.

Over the course of the book, you'll learn about interfacing from Perl to C and C back to Perl. For those that must plug references to Tolkien in things Perl... you can go back and rephrase that into an appropriate reference to Bilbo's book "There and Back Again". You'll also learn the perl api, data structures for core variable types, and how to work with scalars, arrays, hashes, strings, regular expressions, file handles, typeglobs, typemaps, objects, callbacks and PDL with C and C++. And there is even mention of working with Fortran, Java, and more esoteric alternatives.

The book finishes with an in depth look at Perl internals: the parser, tokenizer, op code trees, execution, and compiler. And closes with a discussion of the Perl development process: How it may be monitored and participated in.

What's missing? Detailed coverage of the I/O subsystem and the regular expression engine. I.e., topics which might themselves make for a good book. There was also light coverage on things like scratchpads. There were times while reading when I didn't know whether the issue being discussed was fully covered or curtailed. But you will certainly find better coverage of the issues in this book than elsewhere. This is an impressive book. I hope it will greatly influence the way Perl6 internals are documented.

You can purchase Extending and Embedding Perl from bn.com. Slashdot welcomes readers' book reviews -- to see your own review here, read the book review guidelines, then visit the submission page.

9 of 124 comments (clear)

  1. You are likely to be eaten by a grue by Dynedain · · Score: 4, Funny

    After which you'll probably understand very well references to nethack's 'You are in a maze of twisty little passages all alike.'

    Funny, I remember that exact phrase from Zork.

    --
    I'm out of my mind right now, but feel free to leave a message.....
    1. Re:You are likely to be eaten by a grue by hoggoth · · Score: 4, Informative

      It's not from Zork. It's from the Original Adventure (Colossal Cave). If it's in Zork, it's as a homage to the Original Adventure.

      --
      - For the complete works of Shakespeare: cat /dev/random (may take some time)
  2. misread that title :) by Photon01 · · Score: 4, Funny

    misread that title at first glance, was dreading to see what microsoft had done to perl :)

  3. This is a dead end by Ars-Fartsica · · Score: 3, Informative
    One of the key reasons the Perl 6 project is taking such radical steps in remaking the language is precisely because extending and embedding Perl 5 is HELL.

    Investing in this book and this knowledge at this point is practically a dead-end, as most of the annoying kludges will end with Perl 5.

    Only invest in this book and this knowledge if there is a project you are working on that requires embedding or exteninding perl now. Otherwise wait for the sane cleaned-up world of Perl 6.

  4. Re:Hmm, let's see ... by cmburns69 · · Score: 5, Interesting

    You're dissing perl for being quick and dirty, but just because you can use a shortcut, doesn't mean you have to. I can code with perl and have it come out looking as clean as Pascal (or even *gulp* Java).

    Things can be done in other "structured" languages that would be as unreadable as the most obfuscated perl code. Being able to read your code 9 months from now is more a function of programmer discipline than the language used.

    This game was written in perl, when I was learning, 5 years ago, and because I used good design and comments, I can still read and update the code.

    An online Starcraft RPG? Only at

    --
    Online Starcraft RPG? At
    Dietary fiber is like asynchronous IO-- Non-blocking!
  5. Guide to doing it the hard way? by Andy+Dodd · · Score: 3, Informative

    Or does the book cover easier ways to embed C into Perl, such as SWIG.

    SWIG rocks. SWIG is your friend. I'll agree that extending Perl by embedding C is hell and the documentation sucks, but SWIG makes it all (relatively) easy. With SWIG all you have to do is be careful about data types. (Mainly, you can't directly pass a Perl array to C code, you have to convert it into a C array first. How to handle situations like this with SWIG is well documented.)

    I spent five days trying to figure out how to embed some C functions into Perl. Then I discovered SWIG and was up and running in 3-4 hours.

    --
    retrorocket.o not found, launch anyway?
    1. Re:Guide to doing it the hard way? by cquark · · Score: 3, Informative

      SWIG is much easier to use than XS, but today I prefer Inline, for embedding C, C++, java, python, or whatever other language in which you might be interested in your perl code.

    2. Re:Guide to doing it the hard way? by doop · · Score: 4, Informative
      Or does the book cover easier ways to embed C into Perl, such as SWIG

      There's a whole chapter on "Alternatives to XS", covering SWIG and Inline::*.

  6. twisty passages by syle · · Score: 3, Insightful
    As an experienced C coder, I can happily testify about the need for this book. The man pages to perlembed, perlapi, perlguts are obviously written without regard to the reader actually understanding the content.

    I consider myself a competant programmer, but years of experience have never taught me what it means to 'assign magic to a variable' or deterime the 'taintedness' of a string I found to be magical. Problems of global scope of the loaded programs alone merit a book, or at least a chapter.

    The documention behind it is some of the most befuddled I've ever had this displeasure of witnessing, so nearly all my learning came from studying other programs who managed to do it, along with a brief and ill-advised stint into the garbage collection routines of the interpreter source.

    Merely by existing and being written in English, this is already the best reference on the planet. Hell, it could be written in Klingon and still be more understandable than half the API documents.

    --

    /syle