You will want to either fork or use threads.pm. Here's how with fork:
That is zombie-proofed, but the parent will live, mostly sleeping, until all the kids are done.my %kids; my $maxkids = 2; MAIN: while (1) { # . . . delete $kids{+wait} if $maxkids <= keys %kids; if (condition) { defined(my $pid = fork) or warn "kaboom!" and last MAIN; $pid and $kids{$pid}=1 and next MAIN; %kids = (); # child my $result = OTHER(@args); # child # . . . # more child exit 0; # child ends } } delete $kids{+wait} while %kids; sub OTHER { # . . . }
After Compline,
Zaxo
In reply to Re: create new task from main program
by Zaxo
in thread create new task from main program
by benlaw
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |