tags:

views:

309

answers:

6

I know there is a way to call Perl routines from C. As shown here http://search.cpan.org/dist/perl/pod/perlcall.pod#NAME

But, still I do not see a widespread use of this by C programmers. Has any one used this ...ever? or any idea what are the reasons that it is not used so much?

+6  A: 

Its usually done in reverse. That is, the scripting language coordinates things, and the C program does the processing. The idea is that the code that coordinates is easy to modify, and the code that does the processing runs fast.

The thing to do would probably be to spawn the perl interpreter via the "system" call from C to do something. Probably not quite what you have in mind though.

Matthias Wandel
Not exactly....but still I have a question for some one who has actually used this intensively....what about performance....?
Vaibhav
Performance will be similar to calling the same functions from Perl itself. It will be slower than doing the same in C, but by much and if that's acceptable depends entirely on the problem you're trying to fix.
Leon Timmermans
I agree, performance won't be good. But if you have C code, and care about performance, you probably won't be calling Perl.
Matthias Wandel
+2  A: 
Greg Hewgill
Yep..I agree with you that it is not easy to integrate Perl with C.
Vaibhav
Interestingly, it is easy other way - to integrate C from Perl. You can do it with XS or Inline::C.As for general language interoperability, you can do it in Parrot. But languages based on Parrot are not finished yet.
Alexandr Ciornii
+3  A: 

There are two reasons why one may call a perl function from C: extending and embedding.

In the former case, it isn't all that uncommon actually, but it's rather invisible for outsiders.

What I think your question really is though is "why don't people embed perl more often?" There are a number of reasons for that, it being far more difficult than it should be is the most important one IMHO (see perlcall, perlembed, perlguts and perlapi).

Leon Timmermans
+10  A: 

Well, the most well known example of a C program embedding perl is Apache and mod_perl, which lets people access the Apache API through Perl.

You probably don't see many programs embedding perl because they don't need it as a feature. Why don't more C programs send email? :)

brian d foy
The full version of vim also embeds Perl. The :perldo command is occasionally useful.
Chas. Owens
+3  A: 

Why would I slow down my C program by calling Perl? And I say that as a confirmed Perler. Now, calling into C from Perl, that makes sense (if you need the extra speed).

When one develops in C, it is because they want to trade development time for execution speed.

When one develops in Perl, it is because they want to trade execution speed for development time.

Chas. Owens
You are on to something here -- nobody writes programs that need to "glue" things together in C. It is not good for that.
jrockway
A: 

Many programmers know how to obfuscate C very effectively, without needing to resort to Perl.

Argalatyr
guess I shouldn't tell jokes in church
Argalatyr
+1 for sacred cow hamburgers
DVK
+1 for GSOH, a vital programming skill.
Chris Huang-Leaver