I want to do something akin to the following shell loop in Perl on a computer running Microsoft Windows XP:

while read arg do somecmd $arg -o ${arg}.txt & done <<EOL arg1 arg2 arg3 arg4 arg5 EOL

In other words, I want to iterate a list of arguments and use each one in the invocation of an external program. I want to run the multiple processes simultaneously in the background. I don't really care about stdout or stderr, nor do I care about error checking. (I have another way to check the success or failure of the multiple runs of the command. It's a separate process.)

For me, the trick is emulating in Perl the shell's asynchronous execution à la '&'. I would prefer not to use a module, but I understand I may have to. I'm really looking for the simplest, most straighforward and shell-like solution that gets the job done.

Where is system(1, ...) documented? What does it do? I've seen references to it but I cannot find its documentation.

By the way, I have several Unixish shells installed on the computer and could use one of them for this task. However, the reason I want to use Perl instead of, say, the Korn shell is because the list of arguments isn't actually a trivial one as in the example. Generating and iterating the right arguments in the right order will be much easier to do in Perl than in a shell script.

Jim

UPDATE: Thank you for the helpful responses. I was forced to use the Korn shell after all because it's prohibitively difficult to do this kind of thing in Perl compared to the shell. Instead of using asynchronous processes, I just wrote several separate shell loops (i.e., wrapper scripts) and ran them simultaneous. It worked well. I solved the problem by not programming (or at least "programming" much less).


In reply to Simple Perl "Shell" Script on Windows XP to Run Multiple, Simultaneous Processes in Parallel by Jim

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.