Yes, forking should do, try out Parallel::ForkManager.
MJD says "you can't just make shit up and expect the computer to know what you mean, retardo!" | I run a Win32 PPM repository for perl 5.6.x and 5.8.x -- I take requests (README). | ** The third rule of perl club is a statement of fact: pod is sexy. |
| [reply] [Watch: Dir/Any] |
forking (or threading) is the answer.
Abigail | [reply] [Watch: Dir/Any] |
You don't mention what platform you're on, but here are some alternatives to forking depending on your needs:
If you're on Unix/Linux, and the 'process' you need to start is an external command/program/script, you can just run it in the background using system("$cmd &").
If you're on Windoze, I have heard you can do this to start a program in the background if you don't mind if it has it's own DOS window: system("start $cmd").
Otherwise, use fork, unless you're on Windoze and fork doesn't work there, in which case, look here.
HTH
-- 3dan
| [reply] [Watch: Dir/Any] [d/l] [select] |
Reading between the lines you might do well to run a search on Google for perl tutorial fork for some background reading on this.
BTW IMHO tho' you have purchased worthy and excellent tomes you would probably get more out of them if you added merlyn's excellent Learning Perl to your collection. Oh, and reading it :) | [reply] [Watch: Dir/Any] |
I feared Fork would be the answer. Having stared at the books a while it still doesn't make much sense. However I have a feeling that to do what I want I'd need to fork hundereds of times and I think that would be bad form.
I guess what I'm really after is a true 'fire and forget' entity which Perl doesn't have ('cos it's too responsible). Looks like I might have to use a batch script Yuk
I'd love to add another book to the shelf but I couldn't really justify it as I've still to read the ones I've got. I'll bare it in mind though if some kind sole suggests we need some more reference material. | [reply] [Watch: Dir/Any] |
fork works fine under Win32, but if you want to use system and don't want lots of CMD windows, just use the /B (for background) option on the start command and /c on cmd to make the cmd sessions 'go away' of their own volition.
system( 'start /b cmd /c your_command' );
If you have 5.8 then you can also use threads, the async() function makes this very easy. The following line will do a dir for each subdirectory below your current directory asynchronously.
use threads;
async( sub{ system "dir $_" } )
for grep -d, glob '.\*';
Not a very convincing demo, but it does work.
Examine what is said, not who speaks.
"Efficiency is intelligent laziness." -David Dunham
"When I'm working on a problem, I never think about beauty. I think only how to solve the problem. But when I have finished, if the solution is not beautiful, I know it is wrong." -Richard Buckminster Fuller
If I understand your problem, I can solve it! Of course, the same can be said for you.
| [reply] [Watch: Dir/Any] [d/l] [select] |