原文:
12.10. How do I call perl from C?
You need to see a recent copy of the perlembed(1) pod page. By "recent" it needs to be up to date with at least perl5.002.
Borrowing from Jon Orwant's preamble to that document:
Do you want to: Use C from Perl? Read (at least) the perlcall(1), the perlapi(1), the perlxs(1), the perlxstut(1), and the perlguts(1) manpages. Use C++ from Perl? Recent changes to MakeMaker will make this easier. Be sure you are familiar with the perlcall(1), the perlapi(1), the perlxs(1), the perlxstut(1), and the perlguts(1) manpages. Use an executable program from Perl? Read about backquotes ``, system(), and exec() built in perl functions. Try reading the perlfunc(1) manpage. Use Perl from Perl? Read about do, eval, use and require. The perlfunc(1) manpage discusses these. For complete scripts you may also make use of the backquotes ``, system(), or exec() built in perl functions, but you may take a performance hit in doing so (see perlfunc(1) for information). Use C from C? Rethink your design. Use C++ from C++? See previous. Use Perl from C? Read (at least) the perlembed(1) and the perlguts(1) manpages. Use Perl from C++? Read (at least) the perlembed(1) and the perlguts(1) manpages.
There is also an Doug MacEachern's mailto:dougm@osf.org embedder's development kit on CPAN and at a URL of the following form: http://www.osf.org/~dougm/perl/or http://www.perl.com/cgi-bin/cpan_mod?module=ExtUtils::embed
译文:
12.10 如何在C程序中调用Perl代码?
你应该查阅新近版本的Perl手册页中关于perlembed的内容。这里所谓的“新近版本”应该是至少Perl5.2以上。
(译者注:如果你的系统上已经安装了Perl,那么直接在命令行中使用:perldoc perlembed就可以了。)
下面就是Jon Orwant的手册页的导言部分:(译者注:因为原文可能已经有些过时了,所以下面是按照我自己系统上的Perl手册翻译的。)
如果你需要做下面的事情吗:
在Perl代码中使用C语言?
请阅读perlxstut、perlxs、h2xs、perlguts和perlapi的手册页。
在Perl代码中调用Unix系统程序?
请阅读perlfunc手册页中关于back-quotes,以及"system"和"exec"的部分。
在Perl代码中调用其它的Perl代码?
请阅读perlfunc手册页中关于do、eval、require和use等函数的条目。(译者注:也可以直接使用如下命令行操作:perldoc –f eval等等)
在C程序中调用C程序?
这好像跟我们的话题没有关系咯……:P
在C程序中调用Perl脚本?
读……
另外,互联网上(包括CPAN)还有一个Dong MacEachern开发的专门用于进行嵌入式开发的工具包:
http://www.osf.org/~dougm/perl/
或
http://www.perl.com/cgi-bin/cpan_mod?module=ExtUtils::embed