简体   繁体   中英

Why don't more C programs embed Perl?

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?

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? :)

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.

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 ).

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.

One situation where this is used is in a plug-in or scripting architecture. For example, the irssi IRC client is written in C but supports scripting with Perl .

In my experience however, building irssi with Perl enabled is troublesome and prone to failure. I have had instances where the program wouldn't build at all with Perl bindings enabled (some compile or link failure), and also where the program would compile but would immediately fail on startup with a runtime error. These sorts of problems might explain why it's not terribly popular—calling one language from another is almost never as easy as it is in .Net.

许多程序员都知道如何非常有效地混淆C,而不需要求助于Perl。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM