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:
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. 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. 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!
Of the solutions:
Each of the above methods has advantages and disadvantages. It depends on what you're concerned about:
In the end, if it were me, I'd select either embedding or translating depending on whether it is going to change again.
Now... I wrote a whole system for geocaching that I actually want to translate into Qt because I think it'll be more portable. What's my right choice? Translating. But it's going to take a lot of time, hence the reason I haven't done it yet.
If the perl script isn't very long, may be you should rewrite it in C and forget perl.
Otherwise, i would use a system call. If portability is a concern, you can compile the perl script with perlcc in order to get an exe file which will be fully portable and will save you from installing perl in every machine you want to run this program.
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.