replacing " with `` and ''

Barr3y Jaspan bjaspan at athena.mit.edu
Sun May 5 04:48:51 AEST 1991


In article <DJM.91May3235942 at egypt.eng.umd.edu>, djm at 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 at mit.edu



More information about the Alt.sources mailing list