I have a question about embedding Perl scripts in C. I wrote most of the program in C and a portion of it in Perl. As of right now, to call the Perl script I'm using pipe(), fork() and dup2() to create another process and have the Perl application write its stdout to the pipe. This works fine, but I don't want to have to lug around the Perl script whenever I want to run my program. I understand that I can add a Perl interpreter to my C code, but as far as I can see this leaves me I the same boat as I was previously unless I rewrite my Perl code so that it fits the perlapi.

I was wondering if it is possible to just compile my Perl script into the executable binary and use the embedded Perl interpreter to handle it? Thanks!

Thanks for the reply,
The page Google suggests doesn't quite answer my question though. I would prefer to not have to rewrite any of my Perl script yet still have it within the executable binary.

I know Perl is famous for "batteries included", but C is famous for rolling them little batteries right along, as well. ;)

If you're going to have to re-write it, consider just using C.

Perhaps you should read it more carefully, as there are definitely examples of running Perl code from within C on that page.

That said, it is a bit unusual to call Perl from C and not the other way around. If it's reasonable to do so, another option is to compile your C code into a library and use it from Perl -- of course, this raises some more compatibility issues.

I think you can also compile Perl code into to a native library by linking it with the Perl interpreter somehow, then use that library directly... but I don't know the process.

The "simple way" is to call upon the Perl interpreter directly to do the hard stuff. Since you wish to avoid that approach, everything else is going to be quite a bit more involved.

Sorry, I think you're misinterpreting what I want to do, or maybe I wasn't very clear. I know there are examples of Perl code running from C on that page.
Regardless, I've figured it out, thanks for the help though.

This article has been dead for over six months. Start a new discussion instead.