June 2005
Beginner
480 pages
10h 31m
English
In Perl, patterns are enclosed inside a pattern match operator, which is sometimes represented as m//. A simple pattern might appear as follows:
m/Simon/
The preceding pattern matches the letters S-i-m-o-n in sequence. But where is it looking for Simon? Previously, you learned that the Perl variable $_ is frequently used when Perl needs a default value. Pattern matches occur against $_ unless you tell Perl otherwise (which you'll learn about later). So the preceding pattern looks for S-i-m-o-n in the scalar variable $_.
If the pattern specified by m// is found anywhere in the variable $_, the match operator returns true. Thus, the normal place to see pattern matches is in a conditional expression, as shown here:
if (m/Piglet/) ...
Read now
Unlock full access