C For Perl Programmers?

schwern on 2008-01-18T17:01:18

On p5p I wind up saying "someone who knows C should..." a lot and "I'm not a C programmer, but...". It's healthy to have people on p5p who are native speakers of Perl to reign in the C and shell programmers when the internals start to leak into their Perl (see the ongoing "Infinity is not MAX_INT!" fun) but I'd like to be more useful with the actual coding. If nothing else then to not distract our overworked real C programmers from doing real work on perl with my silly ideas.

So where's the "C for Perl Programmers" book/tutorial/etc...? There's Simon Cozens' old "Embedding and Extending Perl" book, which is handy, and Advanced Perl Programming has a little bit of C in it, and perlguts. But where's the "explaining C insanity in terms of Perl insanity" book? Or even "C for Dynamic Programmers"?

Suggestions?


For what it is worth

Phred on 2008-01-18T21:25:45

For what it is worth, I have been diving into the perl/c goodness in the mod_perl innards as I hack away, so maybe I have something useful to say here. I am a mediocre C programmer (just don't use it that much when I can use Perl), but I know enough to read the C constructs without having to go to the reference book.

So first off, if you don't know C, go get a intro to C book or something like that to at least get an idea of the way functions/variables are typed, etc. Understand what a struct is (think object in some ways). Understand the different data types (char, int, etc.). Take a stab at understanding pointers (char *), but don't quit if you don't understand those right away. Understand how header files are used, #include "foo.h", think use Foo;. Go write hello world in C to get your feet wet.

Now go read some perl source code :) When you run into the idioms you don't see in the C book (SV), go perldoc perlguts and search for that idiom. That has been fairly helpful to me in identifying the basic structures such as SVs and CVs. That document is not light reading, so I have mainly used it for reference. Go read about pTHX_ in perlguts, that's a big one that I wish I had read about sooner. Go read Perlguts Illustrated (may need to find a cached copy).

If you've gotten this far, go try to write some code now, figure out how to implement something you want. It might turn out that you've picked a difficult problem instead of an easy one and you won't make much progress, but you'll learn something, and that process is invaluable. Good luck, please let me know if you find other good resources on this subject.