I currently have a program that I have written in C, and I am interested in integrating into it a fairly lengthy Perl script that someone else wrote that accomplishes a similar function but does so in a different way. I am not interested in translating the entire Perl script into C by hand.
The way I see it there are a few different options:
- Because the script communicates using stdin and stdout, I know that I could use a system call, e.g.
system("perl script.pl")and pipe the input and output, but I feel like this solution is not portable and doesn't feel very elegant. - I could embed the Perl interpreter into my program in order to process the script, however, I feel like this would probably be bulky and would be overkill for executing a script that does not change. This does offer the advantage that instead of piping the input and output I could call the Perl subroutines directly.
- I could use some sort of perl-to-c translation tool (like
perlcc) to compile the Perl source into C source at compile time and then just include it into the rest of my program. Although at first glance I thought this would be the best option there seems to be a wide consensus in the Perl community (or at least the part of it that google showed me) that doing this sort of translation is not a very good idea (this might just be for speed considerations, which are not a problem at all for me). This also (might?) allow me to call the Perl subroutines from within C code which would be a huge plus. - Rewrite the script by hand.
So my question is this: which of these options (or none of the above) is the most elegant and portable? I understand that calling this Perl program from within a C program is already a messy hack to start with, but the least messy solution would probably be best.
Thank you!