Re: [SLUG] String Replacement

From: Jason Copenhaver (jcopenha@csee.usf.edu)
Date: Wed Jul 04 2001 - 14:12:42 EDT


On Wed, 4 Jul 2001, billt wrote:

> On Wed, Jul 04, 2001 at 10:26:55AM -0400, Jason Copenhaver wrote:
> > @files = glob("*.files.to.be.changed");
> > foreach $file (@files)
> > {
> > open(INPUT,">$file");
> > while(<INPUT>)
> > {
> > s/Jim/Jim H./g
> }
> > close(INPUT)
> > }
>
> was just thinking that maybe it should distinguish between something
> like Jim (the guy) and Jimbo's Pit Bar-B-Q (which would end up Jim
> H.bo's Pit Bar-B-Q. --> s!\bJim\b!Jim H.!g (the \b matches word
> boundaries, or anything not \w)
>
> ek, an if the sentence ends in Jim. like
> "...tomorrow we'll go see Jim."
> will end up
> "...tomorrow we'll go see Jim H.."
>
> that's probably ok, but I don't know the rule of style on that one.
>
> s!\bJim\b\.?!Jim H.!g will fix that.
>
> it is never as easy as it sounds :)

true true.. my regexp was just quick and dirty..should definately look at
the different cases..



This archive was generated by hypermail 2.1.3 : Fri Aug 01 2014 - 15:30:21 EDT