Re: [SLUG] String Replacement

From: billt (billt@ifelse.org)
Date: Wed Jul 04 2001 - 11:59:50 EDT


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

 

>
> something like that should work.. i'm coding perl off the top of my head
> here though.. so.. it might not be exactly right..
>
> Jason
>
>



This archive was generated by hypermail 2.1.3 : Fri Aug 01 2014 - 15:29:49 EDT