Acme-Spork
view release on metacpan or search on metacpan
lib/Acme/Spork.pm view on Meta::CPAN
spork(
sub {
sleep 5;
open my $log_fh, '>>', 'spork.log', or die "spork.log open failed: $!";
print {$log_fh} "I am spork hear me spoon\n";
close $log_fh;
},
) or die qq{Couldn't fork for spork: $!};
print 2;
This prints out "12" immediately and is done running, now if you tail -f spork.log you'll see "I am spork hear me spoon\n" get written to it 4 or 5 seconds later by the spork()ed process :)
spork() returns the PID of the spork()ed process so you can keep track of them and do what you need with it.
If it returns false then fork failed so you can:
if(spork(\&foo)) {
print "I am spork here me spoon\n";
}
else {
print "Could not fork for spork: $!";
( run in 1.633 second using v1.01-cache-2.11-cpan-39bf76dae61 )