Dear Monks,

I have 2 files, each split into 10 equal parts. I need to run an external C script with each part as an input (keeping parts of two files separate) and parse and combine the results for the entire file. Simplified example;

foreach my $Index ( 0 .. 10 ) { `Script Input:File_1[$Index], Paramater, Output: 'Results_File_1_'.$In +dex`; @Results_1 = Parse the 'Results_File_1_'.$Index using subroutine and a +ppend to @Results_1; `Script Input:File_2[$Index], Paramater, Output: 'Results_File_2_'.$In +dex`; @Results_2 = Parse the 'Results_File_2_'.$Index using subroutine and a +ppend to @Results_2; } Do something with @Results_1, @Results_2 (both have to finished).

I was wondering if there is an easiest way to fork the processes. I am not familiar with forking and I was thinking about running two processes at once in the background, waiting for them to finish and parse one after another (I am not sure if the appending will not clash if by chance two processes appending to same @Result will try to do it at once). Also I am not sure how to catch errors from the C script (any error should end the script printing the error message). Any suggestions? Many thanks!


In reply to Simplest Forking by Anonymous Monk

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.