Basic HTML version of Foils prepared March 30 97

Foil 42 The Matching Operator in Regular Expressions - I ( =~, m)
(Chapter 7 of the Llama Book)

From PERL4 Tutorial for CPS616 Computational Science for Information Age Course CPS616 -- February 1995. by Geoffrey C. Fox


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



© Northeast Parallel Architectures Center, Syracuse University, npac@npac.syr.edu

If you have any comments about this server, send e-mail to webmaster@npac.syr.edu.

Page produced by wwwfoil on Sat Sep 6 1997