home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1992 March / Source_Code_CD-ROM_Walnut_Creek_March_1992.iso / usenet / altsrcs / 3 / 3289 < prev    next >
Encoding:
Text File  |  1991-05-05  |  1.1 KB  |  34 lines

  1. Newsgroups: comp.lang.perl,alt.sources
  2. From: bjaspan@athena.mit.edu (Barr3y Jaspan)
  3. Subject: Re: replacing " with `` and ''
  4. Message-ID: <1991May4.184851.3472@athena.mit.edu>
  5. Date: Sat, 4 May 91 18:48:51 GMT
  6.  
  7. In article <DJM.91May3235942@egypt.eng.umd.edu>, djm@eng.umd.edu (David J. MacKenzie) writes:
  8. |> Here's a little script I wrote when I needed to typeset some documents
  9. |> that had been written with a word processor.  Anyone have a better way
  10. |> to do this in perl?
  11.  
  12. Well, I won't say this is necessarily ``better,'' but it is how I would have
  13. done it.  Note that instead of keeping track of the $leftquote state, I just
  14. assume some rules about how quotes are used in text (in fact, nearly the same
  15. rules that emacs TeX mode uses).  A " that is followed by a "special symbol"
  16. (which i've defined to be [ \n\t.?,], probably there are others) is assumed to
  17. be a close-quote, and all others are open-quotes.
  18.  
  19.  
  20. #!/afs/athena/contrib/perl/perl
  21.  
  22. $follow_end = "[ \n\t.!?,]";
  23. while (<>) {
  24.     if (! (/^[.\']/ || /^\"/)) {
  25.         s/\"($follow_end)/\'\'$1/g;
  26.         s/\"/\`\`/g;
  27.     }
  28.     print;
  29. }
  30.  
  31.  
  32. -- 
  33. Barr3y Jaspan, bjaspan@mit.edu
  34.