Access to the Shell
Perl can perform for you any process you might ordinarily perform by typing commands to the shell through the \\ syntax. For example, the code in Listing 37.4 prints a directory listing.
Listing 37.4. Using Backticks to Access the Shell
$curr_dir = 'pwd';@listing = 'ls -al';print "Listing for $curr_dir\n";foreach $file (@listing) { print "$file";}
Note
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", ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access