me Banner
TECH
HARDWARE CISCO LINUX MICROSOFT C++ HTML JAVASCRIPT PERL SHELL SCRIPTING SQL NOTES
Prev

Perl Notes

Next

Chapter 12 External Programs and Commands

In Perl, backticks `` and the system() and exec() functions run external programs. Shell escapes should be avoided, as they impose needless security, portability, and maintainability problems. However,...

  • Backticks run a command and returns the command's output
    $A = `pwd`;

    Backquotes provide a means of returning to the Perl process the value generated by the child process that would have been written to STDOUT or another file, had that process been launched through the system() operator. Thus, this form of system call may be better suited in some instances than the system() operator described below.

  • system() runs command and returns command's exit status.
    $A = system("pwd");

    The simplest form of Perl process operator is the system operator. Just as a UNIX shell launches a new process to carry out a command, so the system operator causes Perl to launch a new process to carry out the indicated operation. It takes a single argument, the name of the process or command to be executed, and it returns a success/failure code. However, unlike many other operators, system normally returns a zero if successful and a nonzero value if unsuccessful.

  • exec() runs command and never returns
    exec "pwd";

    The exec operator works much like the system operator except that when it launches another process, the Perl program from which the launch originated immediately terminates.