June 2005
Beginner
480 pages
10h 31m
English
Just finding patterns in strings and lines of input isn't enough; sometimes you need to modify the data as well. One way—but certainly not the only way—is to use the substitution operator s///. The syntax is as follows:
s/searchpattern/replacement/;
The substitution operator searches $_ by default for searchpattern and replaces the entire matched regular expression with replacement. The operator returns the number of matches or substitutions performed, or 0 if no matches were made. The following is an example:
$_="Our house is in the middle of our street". s/middle/end/; # Is now: Our house is in the end of our street s/in/at/; # Is now: Our house is at the end of our street. if (s/apartment/condo/) { # This code isn't reached, ...Read now
Unlock full access