I have never coded in perl before (just started today morning
. I need to write a perl program to automate a task.
Here is how I do it manually:
Start a program in my home dir. Now if I want to execute another program while this one is still running, what I would do is go to another terminal and then run it there in my home dir. While these 2 programs are running and I need to run another program then I will simply start another terminal and run the third one there.
But I want to automate this using perl. So I will have a perl script which will have 3 system calls:
$output1 = `./program1`;
$output2 = `./program2`;
$output3 = `./program3`;
# All 3 programs are finished. Do something with these output strings
But here, program2 will not be started until program1 has returned so it will have to unnecessarily wait. I want all 3 programs to run in parallel. And only once when all system calls have returned, go ahead and process the output strings.
So what do I need to do? use forks or threads ?
(note that Im using backticks `` to execute the system command, but I think there are other ways to do it such as system() etc.. I am free to use anything I want. Also, in the example I take the output in a string.. however I will eventually have the system calls direct the output to a file)
Thanks !!!