|
-
Mar 6th, 2002, 03:37 PM
#1
Thread Starter
Stuck in the 80s
Replace
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?
-
Mar 6th, 2002, 04:04 PM
#2
Fanatic Member
-
Mar 7th, 2002, 11:56 AM
#3
Black Cat
Use Regular Expressions, one of the greating things in Perl and imitated by many other languages.
http://www.troubleshooters.com/codec...rl/perlreg.htm
Josh
Get these: Mozilla Opera OpenBSD
I have books for sale: "MCSD in a Nutshell" and "VB Distributed Exam Cram" - PM me for details. Will also trade for a decent ATX Pentium 2 MB/CPU/RAM combo.
-
Mar 7th, 2002, 02:45 PM
#4
Thread Starter
Stuck in the 80s
So I would do something like:
Code:
$string = "The dog is a flick rat-tat-tat."
$string =~ tr/a/ae/;
To get "The dog is ae flick raet-taet-taet" ??
(This isn't the exact thing I'm doing, just an example)
-
Mar 7th, 2002, 02:55 PM
#5
Black Cat
Code:
$string = "The dog is a flick rat-tat-tat.";
$string =~ s/a/ae/;
print "$string\n";
tr is another function, not a RegExp.
Josh
Get these: Mozilla Opera OpenBSD
I have books for sale: "MCSD in a Nutshell" and "VB Distributed Exam Cram" - PM me for details. Will also trade for a decent ATX Pentium 2 MB/CPU/RAM combo.
-
Mar 7th, 2002, 03:04 PM
#6
Thread Starter
Stuck in the 80s
Alright, that works, but when I try to do something like this:
Code:
$string = "My Name is Bill (William)";
$string =~ s/(/ ( /;
print "$string\n";
But it craps out on me?
-
Mar 8th, 2002, 12:51 PM
#7
Black Cat
Originally posted by The Hobo
Alright, that works, but when I try to do something like this:
Code:
$string = "My Name is Bill (William)";
$string =~ s/(/ ( /;
print "$string\n";
But it craps out on me?
( and ) have special meaning - escape them like this:
Code:
$string =~ s/\(/ \( /;
Josh
Get these: Mozilla Opera OpenBSD
I have books for sale: "MCSD in a Nutshell" and "VB Distributed Exam Cram" - PM me for details. Will also trade for a decent ATX Pentium 2 MB/CPU/RAM combo.
-
Mar 8th, 2002, 03:59 PM
#8
Thread Starter
Stuck in the 80s
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|