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

Re: how do you do string substitution in perl ?



Or, you could try (real code :):

s/\b:\)\b/smiley/g;
s/\brtfm\b/read the fucking manual/g;

you don't need the if statements -- just run th regex -- it'll only work
if the match is valid.  If ther's no match, it won't happen.  Trying to 
process spoken text lexicly is _really_ hard -- espeically when you consider
that people make mistakes, and can accomodate for it when reading the 
mistakes!  If you can figure out how to do this well, you'll easily be able
to make millions of dollars...

kyle

------------------------------------------------------------------------------
Premature optimization is the root of all evil. 
    -- D.E. Knuth
mortis@voicenet.com                            http://www.voicenet.com/~mortis
------------------------------------------------------------------------------

On Mon, 14 Dec 1998 jstelzer@vertical.net wrote:

> 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
> 
> 

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