How would I go about making a Replace function in CGI/Perl?
If I wanted to replace all the j's in a variable with p's, how could I do it?
Printable View
How would I go about making a Replace function in CGI/Perl?
If I wanted to replace all the j's in a variable with p's, how could I do it?
This might be helpful I dont know :)
http://www.ictp.trieste.it/texi/perl/perl_31.html
Use Regular Expressions, one of the greating things in Perl and imitated by many other languages.
http://www.troubleshooters.com/codec...rl/perlreg.htm
So I would do something like:
To get "The dog is ae flick raet-taet-taet" ??Code:$string = "The dog is a flick rat-tat-tat."
$string =~ tr/a/ae/;
(This isn't the exact thing I'm doing, just an example)
tr is another function, not a RegExp.Code:$string = "The dog is a flick rat-tat-tat.";
$string =~ s/a/ae/;
print "$string\n";
Alright, that works, but when I try to do something like this:
But it craps out on me? :confused:Code:$string = "My Name is Bill (William)";
$string =~ s/(/ ( /;
print "$string\n";
( and ) have special meaning - escape them like this:Quote:
Originally posted by The Hobo
Alright, that works, but when I try to do something like this:
But it craps out on me? :confused:Code:$string = "My Name is Bill (William)";
$string =~ s/(/ ( /;
print "$string\n";
Code:$string =~ s/\(/ \( /;
ah, I should have known that.
Thanks for all this help, Josh! It would have taken me forever to figure all this out on my own. Thanks again. :)