Should one really use external commands while coding in Perl? I see several disadvantages of it. It’s not system independent plus security risks might also be there. What do you think? If there is no way and you have to use the shell commands from Perl then what is the safest way to execute that particular command (like checking pid, uid etc)?
Should one really use external commands while coding in Perl? I see several disadvantages
Share
It depends on how hard it is going to be to replicate the functionality in Perl. If I needed to run the
m4macro 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 ofreaddir()et al plusstat()orlstat()inside Perl is more sensible than futzing with the output ofls.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 alsoexec), etc, rather than a single string for the command plus arguments (which means the shell is used to process the command line).