djm@eng.umd.edu (David J. MacKenzie) (05/04/91)
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? #!/usr/local/bin/perl # Change " to `` and '' for typesetting. # Leave unchanged lines that start with `.', `'', or `\"', # because they are probably troff code. # David MacKenzie, djm@eng.umd.edu $leftquote = 1; while (<>) { if (!(/^[.\']/ || /^\\\"/)) { while (/\"/) { if ($leftquote) { s/\"/\`\`/; } else { s/\"/\'\'/; } $leftquote = !$leftquote; } } print; } -- David J. MacKenzie <djm@eng.umd.edu> <djm@ai.mit.edu>
bjaspan@athena.mit.edu (Barr3y Jaspan) (05/05/91)
In article <DJM.91May3235942@egypt.eng.umd.edu>, 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