next up previous contents
Next: The Translation Operator (tr///) Up: The Matching Operator (m//) Previous: The Matching Operator (m//)

The Matching Options

The matching operator has several options that enhance its utility, similar to substitution. The most useful option is probably the capability to ignore case and to create an array of all matches in a string. The options are:

All options are specified after the last pattern delimiter. For instance, if you want the match to ignore the case of the characters in the string, you can do this (match4.pl):

$_ = "AAA BBB AAA";
print "Found bbb\n" if  m/bbb/i;

This program finds a match even though the pattern uses lowercase and the string uses uppercase because the /i option was used, telling Perl to ignore the case.

The result from a global pattern match can be assigned to an array variable or used inside a loop. This feature comes in handy after you learn about meta-characters in the section called "How to Create Patterns" later in this chapter.

For more information about the matching options, see the section, "Pattern Examples" later in this chapter.


next up previous contents
Next: The Translation Operator (tr///) Up: The Matching Operator (m//) Previous: The Matching Operator (m//)
dave@cs.cf.ac.uk