[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: how do you do string substitution in perl ?



Quasi code:
if ( $_ =~ /\s+|^ :\)\s+|$  ){
    $_ =~ s/:\)/smiley/g
    }
elsif ( $_ =~ /\s+rtfm\s+ ) {
     $_ =~ s/rtfm/read the fucking manual/g
     }

Ok, thats probably not perfect syntax, but I'm in a hurry. You want 
to make sure you're not substituting it willynilly. So if its part
of annother string or what not you may not always want to substitute
it. I'm jsut seeing if its surrounded by white space, at the begining
or end of a line. In fact you may get better milage with a bunch of 
simple harder to screw up elseif statements rather than trying to 
do it all in one line.

Hope that helps.

 Jason Stelzer
 Systems Administration
 VerticalNet, Inc.
 jstelzer@verticalnet.com

"Fear not the dark within this night
  Beneath the sky of deadly light.
  Of raging fire seen from afar:
 The fear inside of who you are."

On Sat, 12 Dec 1998, Darxus wrote:

> 
> Okay, say I have a string substitution list, that includes, 
> 
> ":)" "smile"
> "rtfm" "read the fucking manual"
> 
> And I have a string that says
> 
> "rtfm you fool :)"
> 
> And I want to have the above string and the above table to output:
> 
> "read the fucking manul you fool smile"
> 
> So how do I do that in perl ? 
> ________________________________________________________________________
> ***PGP fingerprint = D5 EB F8 E7 64 55 CF 91  C2 4F E0 4D 18 B6 7C 27***
>                darxus@op.net / http://www.op.net/~darxus 
>                            You do not exist.
> 
> 
> --
> To unsubscribe, send a message with the word 'unsubscribe' in the subject
> or body of your message to speech-request@lists.nothinbut.net
> 

--
To unsubscribe, send a message with the word 'unsubscribe' in the subject
or body of your message to speech-request@lists.nothinbut.net