Does knowing C help write Perl?

Out of some weird sense of completeness, I've decided recently to put some effort into learning C. I'd like to understand more about how things actually work, and I'd like to be able to contribute in some more serious way to projects, like Perl, that I like. Also, I had the vague notion that it would make my Perl better.

This is really hard. I'm not a math type, and I've never understood much about pure comp science, so everything is really confusing. I've been working through K&R, which is really advanced. (Aside: I also bought the Oualline book from O'Reilly, which has a weird set of Amazon reviews--some one-star reviews saying "this is too hard!", and then five-star reviews saying "this is real programming--get over it! It's a great book." However, the book is a joke compared to K&R. 70 pages into it, you're still on "Hello, world!" level stuff, while K&R has you working out genuinely difficult things from about page 5.)

First of all, every exercise, I think "I could do this in Perl in about seventeen characters." Perhaps that's the point. But I also find that I often have a good sense of how to do something, I just don't know how to execute it. And I spend all my debugging time realizing that I meant

i <= len

, not

i < len

, etc. If I wanted to have to know math, I wouldn't have read Classics. I'm also not sure what Perlish practices should be used in C, or what will make me look like a dork--e.g. using curly braces around single statements in C:

for (i = 0; i < MAX; ++i) { printf("%d: %d",i,value(i)); }

I'm beginning to wonder what the point of all this is. I'll never be good enough at C to actually contribute to the Perl core, or to debug perl. Will this make me a better person? Will it improve my Perl code?

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
Without JavaScript enabled, you might want to
use the classic discussion system instead. If you login, you can remember this preference.

Please Log In to Continue

I doubt that learning C will make you a better Perl programmer, though it's certainly a handy language to know. If anything, it will make you appreciate Perl that much more.

Where it may help you later on is analyzing extensions that folks have written should you ever delve into their source code. Or perhaps one day you'll even look at the (*gasp*) Perl source code and actually understand it!

As for good books, I think ORA's Practical C Programming is a pretty good beginners book and Sam's C Primer Plus is a good book all-around.

One time I snuck down to Philadelphia to hear MJD talk about something interesting. During the intermission I spoke with someone (can't remember name now) about Perl and C, and he described C as the Latin of programming languages. So many languages borrow their syntax and style from it that it is useful to know. Many people will use interpreted languages like perl, python, java, php which are implemented in C. So like Latin, C isn't always used directly all that often, but an understanding of it can illuminate your understanding of other languages that you may use more frequently. I don't think he meant that C was a dead language by any means, but just that it occupied this special place. I also have been meaning to learn more C, reading books etc. One that I saw mentioned on the london.pm list, and which I'm really enjoying right now is Expert C Programming [amazon.com]. I'm not an expert by any means, but this book makes a really good follow on to K&R since it talks about the edges of C, and doesn't eschew the strangeness of C. Anyhow, good luck, and keep going! You might want to look at the Perl6 development that is going on as well.