Results 1 to 8 of 8

Thread: Replace

  1. #1

    Thread Starter
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256

    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?
    My evil laugh has a squeak in it.

    kristopherwilson.com

  2. #2
    Fanatic Member Gimlin's Avatar
    Join Date
    Dec 2001
    Location
    Hell
    Posts
    734
    This might be helpful I dont know

    http://www.ictp.trieste.it/texi/perl/perl_31.html

  3. #3
    Black Cat JoshT's Avatar
    Join Date
    Nov 2000
    Location
    WNY, USA
    Posts
    4,032
    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.

  4. #4

    Thread Starter
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    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)
    My evil laugh has a squeak in it.

    kristopherwilson.com

  5. #5
    Black Cat JoshT's Avatar
    Join Date
    Nov 2000
    Location
    WNY, USA
    Posts
    4,032
    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.

  6. #6

    Thread Starter
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    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?
    My evil laugh has a squeak in it.

    kristopherwilson.com

  7. #7
    Black Cat JoshT's Avatar
    Join Date
    Nov 2000
    Location
    WNY, USA
    Posts
    4,032
    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.

  8. #8

    Thread Starter
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    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.
    My evil laugh has a squeak in it.

    kristopherwilson.com

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width