O'Reilly logo

Ubuntu Unleashed 2013 Edition: Covering 12.10 and 13.04, Eighth Edition by Matthew Helmke

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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", ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required