match the text mary in the word maryland.
fred Replaces anything that was matched with the text fred.
/ Ends replace text.
g Does this substitution globally; that is, replaces the match text
wherever in the string you match it (and any number of times).
i The search text is not case-sensitive. It matches bob, Bob, or
bOB.
; Indicates the end of the line of code.
If you are interested in the details, you can get more information using the
regex (7) section of the man page by entering man 7 regex from the
command line.
Although replacing one string with another might seem a rather trivial task,
the code required to do the same thing in another language (for example, C) is
rather daunting unless supported by additional subroutines from external
libraries.
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
46.4 prints a directory listing.
LISTING 46.4 Using Backticks to Access the Shell
Click here to view code image
$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.