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.
$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", ...
Get Ubuntu Unleashed 2013 Edition: Covering 12.10 and 13.04, Eighth Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.