We have finally finished study of regular expressions and have illustrated this for substitution operator (s) acting on default variable $_. We can generalize this operation in many ways
|
The result of ( Variable Name =~ /Regular Expression/ ) is true if and only if value of Variable Name matches Regular Expression. For example
|
if ( <STDIN> =~ /^(T|t)(O|o):/ ) { # <STDIN> is $_
-
..; # Process to: field of mail } # matches if current input
-
line contains to: with any case at start of line
|
There is an implied match operator above which we can make explicit with m
|
$line =~ m/^(T|t)(O|o):/ and we can use m to change delimiter from / to any character and
|
$line =~ m%^(T|t)(O|o):% # is equivalent to previous statement
|
Note m/^to:/i equivalent to above as modifier i instructs pattern match to ignore case
|