Search code examples
cperlembedded-language

How do I compile Perl code within a C program?


I have a C program with an embedded Perl interpreter. I want to be able to precompile some Perl code from within the program. How do I do that?

Rationale (if anyone is interested) is to be able to compile it once, store the parse tree, and execute many times (as long as the compiled code does not change).

Thanks! Madhu

PS: I am using Perl-5.8, though it would be good to know if Perl-6.0 makes this easier in any way.


Solution

  • This is the default behavior when you embed the Perl interpreter in a C program. After you've run perl_parse() to parse the Perl program, you can use perl_run() and call_argv() over and over with the same parsed Perl program.