next up previous
Next: Spilt() and join() Up: Some useful Perl Previous: Setting the Target Operator

Substitution

We may frequently need to change a pattern in a string. The substitution operator (s) is the simplest form of substitution. It has the form:

s/old_regex/new_string/

So to replace the + characters from CGI input with a space we could do:

$CGI_in_val =~ s/\+/ /ge;

We can qualify the substitution with a g global substitution, i ignore case and e evaluate right side as expression and others.

Note: cgi-lib.pl does this and other cgi character conversion automatically.



Dave Marshall
9/28/2001