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 40.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:
Get Ubuntu Unleashed 2014 Edition: Covering 13.10 and 14.04,Ninth 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.