It depends on how hard it is going to be to replicate the functionality in Perl. If I needed to run the m4
macro processor on something, I'd not think of trying to replicate that functionality in Perl myself, and since there's no module on http://search.cpan.org/ that looks suitable, it would appear others agree with me. In that case, then, using the external program is sensible. On the other hand, if I needed to read the contents of a directory, then the combination of readdir()
et al plus stat()
or lstat()
inside Perl is more sensible than futzing with the output of ls
.
If you need to execute commands, think very carefully about how you invoke them. In particular, you probably want to avoid the shell interpreting the arguments, so use the array form of system
(see also exec
), etc, rather than a single string for the command plus arguments (which means the shell is used to process the command line).
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…