Extending and Embedding Perl
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.
>Things like NULL being used throughout chapter 3, only to finally be defined later in a footnote in chapter 4.
... of course I tend to immediately not listen to anything they say anymore, but some have produced code that does work. I hate to imagine what else they don't know... especially about other important stuff like security and database efficiency.
You said yourself that this book is intended for experienced programmers. If you don't know what a NULL is as well as the implications, and are a programmer, you are in deep doo doo. You definitely cannot be considered to be an advanced programmer. I am suprised this book even defines NULL.
However, I have seen a lot of programmers that have trouble and bugs related to NULL values
l8,
AC
use Perl or die();
... well ... Windows crap. Gawd I hate MFC. But that's another story.
s ThemOnSeparateLines {}
I use PHP for web interfaces, Perl for unix scripts, and C++ for
PHP's function handling has a certain ellegance that Perl seems to totally and completely lack.
function MyFunction($line1, $line2)
{
print $line1 . "\n" . $line2;
}
vs.
sub MyFunction {
my ($line1, $line2) = @_;
print $line1 . "\n" . $line2;
}
People argue with me endlessly that perl's method "isn't a hassle". I use Eclipse to edit PHP, and thanks to an add-on, whenever I'm working on a PHP page, I have instant access to every function and object in that file, complete with the function prototype - at a glance, I can see what any given function needs as input. And, given the fact that all of those variables in the prototype are named, one can indirectly provide information on what the whole function is intended to do, if the function name and variable names are written properly.
I suppose there's always the alternative.
sub MyPerlFunctionWhatTakesTwoScalarVariablesAndPrint
But like I said, I prefer PHP's method.
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
... to handle an arbitrary number of arguments
PHP:
function MyFunctionWith2Args($line1, $line2)
{
print $line1 . "\n" . $line2;
}
function MyFunctionWith3Args($line1, $line2, $line3)
{
print $line1 . "\n" . $line2 . "\n" . $line3;
}
function MyFunctionWith4Args($line1, $line2, $line3, $line4)
{
print $line1 . "\n" . $line2 . "\n" . $line3 . "\n" . $line4;
}
You get the picture...
Perl:
sub MyFunction {
print join( "\n", @_ );
}
this works for any number of arguments. Perl's argument passing semantics are inherently varardic. I prefer this rather than having to define n number of functions for n possibilities of argument passing.
In the course of every project, it will become necessary to shoot the scientists and begin production.