The -- notation uses the backtick found above the Tab key (on most keyboards), not the single quotation mark.

You can also use the shell module to access the shell. shell is one of the standard modules that comes with Perl; it allows creation and use of a shell-like command line. Look at the following code for an example:

use Shell qw(cp);

cp ( "/home/httpd/logs/access.log" , "/tmp/httpd.log") ;

This code almost looks like it is importing the command-line functions directly into Perl. Although that is not really happening, you can pretend that the code is similar to a command line and use this approach in your Perl programs.

A third method of accessing the shell is via the system function call:

$rc = Oxffff & system('cp /home/httpd/logs/access.log /tmp/httpd.log'); if ($rc == 0) {

print "system cp succeeded \n"; } else {

print "system cp failed $rc\n";

The call can also be used with the or die clause:

system('cp /home/httpd/logs/access.log /tmp/httpd.log') == 0 or die "system cp failed: $?"

However, you can't capture the output of a command executed through the system function.



Was this article helpful?

0 0

Post a comment