
| Contents |
|||||||||||||||
| [an error occurred while processing this directive] |
6.3 Pattern Matching
Now that you are familiar with some of the basics of regular
expressions, you probably want to know how to use them in Perl. Doing
so is very easy. There is an operator, Consider the following code sample: use strict; while ( defined($currentLine = <STDIN>) ) { if ($currentLine =~ /^(J|R)MS speaks:/) { print $currentLine; } } This code will go through each line of the input, and print only those lines that start with "JMS speaks:" or "RMS speaks:". |