1 |
Regular expressions should be familiar as they are used in many UNIX commands with grep being the best known
-
% grep pattern file; # Print each line of a file containing pattern
|
2 |
Consider the simple pattern /Fox/. We can write the PERL version of grep as follows:
|
3 |
$line = 0;
|
4 |
while (<>) {
|
5 |
if ( /Fox/ ) {
|
6 |
}
|
7 |
$line++;
|
8 |
}
|
9 |
Another familiar operator is s in sed (the batch or stream line editor) where
|
10 |
s/Pat1/Pat2/; # substitutes Pat1 by Pat2 in each line
|
11 |
We'll have more to say about the s operator later
|