Sometimes you need to call an external program and you cannot continue before this program completes its run (e.g., if you need it to return some result). In this case, the fork solution doesn't help. There are a few ways to execute such a program. First, you could use system( ):
system "perl -e 'print 5+5'"
You would never call the Perl interperter for doing a simple calculation like this, but for the sake of a simple example it's good enough.
The problem with this approach is that we cannot get the results printed to STDOUT. That's where backticks or qx( ) can help. If you use either:
my $result = `perl -e 'print 5+5'`;
or:
my $result = qx{perl -e 'print 5+5'};
the whole output of the external program will be stored in the $result variable.
Of course, you can use other solutions, such as opening a pipe (|) to the program if you need to submit many arguments. And there are more evolved solutions provided by other Perl modules, such as IPC::Open2 and IPC::Open3, that allow you to open a process for reading, writing, and error handling.
 
Continue to: