|
I was just modifying a Perl program so I could use a regular expression to
search for all less-than (<) and greater-than (>) symbols, and replace those
with their HTML equivalents tags ("<", and ">", respectively). Here's the
simple Perl code to perform this search-and-replace operation:
open(MY_FILE,$fileName);
my @fileContents = (<MY_FILE>);
close(MY_FILE);
for (@fileContents)
{
s/>/>\;/;
s/</<\;/;
}
This Perl program does the following:
- Open a file, where the file is given by the variable
$fileName.
- Read the contents of the file into the Perl array variable
@fileContents.
- Closes the file.
- Loops through each element in the
@fileContents array, and
does the desired search-and-replace operations.
|