home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!olivea!decwrl!sdd.hp.com!usc!rpi!uwm.edu!linac!att!news.cs.indiana.edu!nstn.ns.ca!dragon.acadiau.ca!merlin!peter
- From: peter@merlin.acadiau.ca (Peter Steele)
- Newsgroups: comp.lang.perl
- Subject: Simultaneous processes
- Message-ID: <root.714838821@merlin>
- Date: 26 Aug 92 14:20:21 GMT
- Sender: news@dragon.acadiau.ca
- Organization: Acadia University
- Lines: 76
- Nntp-Posting-Host: merlin
-
- How does one set up simultaneous processes in perl? For example,
- how would I translate the following into perl:
-
- #!/bin/sh
-
- ls -la > d1 &
- ls -la > d2 &
- ls -la > d3 &
- wait
- cat d1 d2 d3 > d4
-
- This is a pretty simplistic example, but illustrates what I want to
- do in perl. The real program looks like this:
-
- #!/lbin/perl
-
- @dlist1 = split(/,/,$ARGV[0]);
- @dlist2 = split(/,/,$ARGV[1]);
-
- for ($i = 0; $i <= $#dlist1; $i++) {
- for ($j = -1; $j <= $#dlist2; $j++) {
- foreach $d (@dlist1[0..$i]) {
- spawn a process for $d and save its output somehow &
- }
- foreach $d (@dlist2[0..$j]) {
- spawn a process for $d and save its output somehow &
- }
- wait for all processes to complete and combine output;
- }
- }
-
- This program takes two comma-separated lists and loops over the
- values provided. If the program is called "fred", it would be
- called as, for example,
-
- fred d1,d2 e1,e2,e3
-
- The loops generate sets of values in the following pattern:
-
- d1
- d1,e1
- d1,e1,e2
- d1,e1,e2,e3
- d1,d2
- d1,d2,e1
- d1,d2,e1,e2
- d1,d2,e1,e2,e3
-
- I want to spawn off simulataneous processes like this:
-
- do something with d1 &
- wait
- collect combined output
-
- do something with d1 &
- do something with e1 &
- wait
- collect combined output
-
- and so on, with the last interation generating
-
- do something with d1 &
- do something with d2 &
- do something with e1 &
- do something with e2 &
- do something with e3 &
- wait
- collect combined output
-
- Conceptually straightforward, but I'm not sure how to accomplish this
- in perl. I'd also be happy with a pure Bourne shell solution. In fact,
- that would probably be preferable. Does anyone know how to translate
- the for loops above into shell?
- --
- Peter Steele Unix Services Manager peter.steele@acadiau.ca
- Acadia Univ., Wolfville, NS, Canada B0P 1X0 902-542-2201 Fax: 902-542-4364
-