laziness, impatience, and hubris | |
PerlMonks |
Re^2: Passing a structure from C to Perlby bliako (Monsignor) |
on Mar 23, 2018 at 01:27 UTC ( [id://1211579]=note: print w/replies, xml ) | Need Help?? |
Corion's advice is fine but in the case of running the C program many times in parallel, or the perl script is called in a fork many times, you will need to construct the parameter files' names such that they don't overwrite each other. That will probably involve the PID of the C program/children. If this is the case, I would keep the suggestion of formatting the perl script's parameters as a single JSON or XML string but avoid writing it to a file. Instead, pass that string to the perl program as a command line parameter:
Instead of what you now have:
The perl script will then decode the parameters string (whereas in Corion's advice the perl script will read the parameters file and decode its contents). The maximum length of a command line will be limited depending on OS. You have to be careful with quotes. If quotes or special characters are a problem, a quick hack would be to encode your parameter string using base64 and pass that to perl script which it will have to decode it and parse it. It will require more processing time though:
In Section
Seekers of Perl Wisdom
|
|