On Wed, Sep 11, 2002 at 12:17:55PM -0400, Chad Kellerman wrote:
> my @list = "bla, bla, bla, bla, bla";
You probably meant @list = ("bla", "bla", "bla", "bla", "bla");
> foreach my $item(@list) {
> my $pid;
> FORK: {
> if ($pid=fork) {
> print"$pid\n";
> }elsif (defined $pid){
> #do other perl stuff to $item
> exit 0;
> } elsif ($! =~/No more process/) {
> sleep 5;
> redo FORK;
> }
> }
> }
>
> What I want to do, is have the fork, process $item before it goes
> onto the next $item. But as it is written it forks every $item in the
> @list.
>
> Just fork, finish, repeat until all $item are done.
What is the point of forking if you're waiting for the sub-process to
complete before continuing on?
The solution, of course, is to wait, see perldoc -f wait and perldoc -f
waitpid. Another solution is to remove the fork altogether, and simply
process the item in the parent.
Michael
--
Administrator www.shoebox.net
Programmer, System Administrator www.gallanttech.com
--
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]