What do you do when there isn’t “More than One Way to Do It” in Perl? You reach beyond the core language, to a CPAN module and/or external C library -- or you write your own. But, as Tim Jenness and Simon Cozens observe, “writing extensions to Perl has historically been a bit of a black art.” In Extending and Embedding Perl, they empower experienced Perl scripters to perform all sorts of magic.
Jenness and Cozens begin with an overview of C for Perl programmers (while the language will seem barren to those unfamiliar with it, Perl’s syntax borrows heavily from C). They review how Perl modules work, how Perl interfaces with other languages via XS, how Perl variables are represented within Perl, and how to use the Perl 5 API to integrate C and Perl code. In most cases, the authors’ code examples aren’t just realistic: They’re actually taken from real XS modules and Perl sources.
Gradually, the authors move on to more complex integration tasks; for example, handling structures, arrays, and callbacks; linking to C++, Fortran, and (briefly) Java; and using alternatives to XS. Then, they switch gears, showing how to link an entire Perl interpreter inside a C program -- making that program more extensible, flexible, and easier to configure. (GIMP and gnumeric each use this technique extensively). This is slick stuff, well explained. Bill Camarda
Bill Camarda is a consultant, writer, and web/multimedia content developer. His 15 books include Special Edition Using Word 2000 and Upgrading & Fixing Networks For Dummies®, Second Edition.