Perl scripts as a standalone process at run time, invoking another script means creating a child process, which is fundamentally different from a function call, which is a process in which a separate code is executed. This is a special need to pay attention to the premise, the following summarizes the advantages and disadvantages of this mechanism.
Advantages
- Parallelism. Processes are independent and concurrent, so when scripts invoke scripts, both scripts can work in parallel, sub-scripts can call sub-scripts, and parallelism can be infinitely expanded and run efficiently.
- Compatibility. A single line of command can invoke other scripting languages, even system commands, simple and convenient.
Disadvantages
- Special inspection is required to pass parameters. When invoking a script, the incoming parameter is equal to the argument when the command is knocked, and the invoked script does not proactively check that the parameters meet the requirements and needs to be checked separately when writing the script.
- There is no return value after invoking the script. One workaround is that the child script prints the information in standard output, and the parent script captures the information in an inverted quotation mark.
- Standard error messages for child script output require special handling to be captured by the parent script. The standard error output cannot be captured because the anti-quote syntax captures only sub-script standard output.
- Scripts running in the background will not be killed by CTRL + C. If the child script that is called is running in the background
&
, it will mask the signal to kill the process, and the child script is still running after the parent script is killed.
Advantages and disadvantages of Perl script invocation