Xref: utzoo comp.lang.perl:5195 alt.sources:3700 Newsgroups: comp.lang.perl,alt.sources Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!think.com!snorkelwacker.mit.edu!bloom-picayune.mit.edu!athena.mit.edu!bjaspan From: bjaspan@athena.mit.edu (Barr3y Jaspan) Subject: Re: replacing " with `` and '' Message-ID: <1991May4.184851.3472@athena.mit.edu> Sender: news@athena.mit.edu (News system) Organization: Massachusetts Institute of Technology References: Date: Sat, 4 May 91 18:48:51 GMT Lines: 27 In article , djm@eng.umd.edu (David J. MacKenzie) writes: |> Here's a little script I wrote when I needed to typeset some documents |> that had been written with a word processor. Anyone have a better way |> to do this in perl? Well, I won't say this is necessarily ``better,'' but it is how I would have done it. Note that instead of keeping track of the $leftquote state, I just assume some rules about how quotes are used in text (in fact, nearly the same rules that emacs TeX mode uses). A " that is followed by a "special symbol" (which i've defined to be [ \n\t.?,], probably there are others) is assumed to be a close-quote, and all others are open-quotes. #!/afs/athena/contrib/perl/perl $follow_end = "[ \n\t.!?,]"; while (<>) { if (! (/^[.\']/ || /^\"/)) { s/\"($follow_end)/\'\'$1/g; s/\"/\`\`/g; } print; } -- Barr3y Jaspan, bjaspan@mit.edu