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:

perlscript.pl '{"a":"1","b":"2"}'

Instead of what you now have:

perlscript.pl -a 1 -b 2

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:

perlscript.pl 'eyJhIjoiMSIsImIiLCIyIn0='

In reply to Re^2: Passing a structure from C to Perl by bliako
in thread Passing a structure from C to Perl by drpraveena

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.