home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #3 / NN_1993_3.iso / spool / comp / lang / perl / 7933 < prev    next >
Encoding:
Text File  |  1993-01-21  |  2.8 KB  |  104 lines

  1. Newsgroups: comp.lang.perl
  2. Path: sparky!uunet!srvr1.engin.umich.edu!batcomputer!cornell!uw-beaver!fluke!inc
  3. From: inc@tc.fluke.COM (Gary Benson)
  4. Subject: Re: Short sample program needed
  5. Message-ID: <1993Jan21.184849.13619@tc.fluke.COM>
  6. Organization: John Fluke Mfg. Co., Inc., Everett, WA
  7. References: <1993Jan18.214646.2924@pacdata.uucp>
  8. Date: Thu, 21 Jan 1993 18:48:49 GMT
  9. Lines: 93
  10.  
  11. In article <1993Jan18.214646.2924@pacdata.uucp> jimh@pacdata.com (Jim Harkins) writes:
  12. >I should say right off the bat that I don't know perl.  With that out of the
  13. >way, I need a short sample perl program that will convert TeX input into
  14. >a syllabus.  For example, given the input:
  15. >
  16. >\section{Online documentation}
  17. >    \subsection{Unix rule \#1 - RTFM}
  18. >    \begin{itemize}
  19. >        \item Online manual (man) pages
  20. >        \item Readme files (e.g. /usr/local/gnu-src/README)
  21. >        \item Large manuals (e.g.
  22. >        /usr/local/gnu-src/g960/doc/misc/gcc/gcc-user.ms, over 200 pages of
  23. >        documentation on gcc.
  24. >        \item Look for files ending with .ms, .man, .tex.
  25. >    \end{itemize}
  26. >
  27. >        \subsubsection{Scooby doobie doo}
  28. >            .....
  29. >    \subsection{Man is your friend}
  30. >
  31. >I need the output
  32. >
  33. >Online documentation
  34. >    Unix rule #1 - RTFM
  35. >        Scooby doobie doo
  36. >    Man is your friend
  37. >
  38. >All I care about are section, subsection, and subsubsections.  I can ignore
  39. >little stuff like the backslash in front of the #.
  40.  
  41.  
  42. This is very easy in perl, one of the first types of things that many people
  43. first use perl to do: a good choice for an introductory class, in my
  44. opinion!. My little attempt below meets your requirements for not using
  45. trickery and for a straightforward approach to just doing the job. I have
  46. included one "feature", though: a subroutine to do any kind of cleaning up
  47. you might like, for example that ugly \# thing.
  48.  
  49. Here's my try:
  50.  
  51. #! /usr/local/perl -d
  52.  
  53. $debug if $d;
  54. print "$0: A Definite Improvement over AWK!!\n" if $debug;
  55.  
  56. while (<>) {
  57.  
  58.     if (/\\section{(.*)}/) {
  59.       &dosubs();
  60.       print "\n$line\n";
  61.       next;
  62.     }
  63.     if (/\\subsection{(.*)}/) {
  64.       &dosubs($line);
  65.       print "\t$line\n";
  66.       next;
  67.     }
  68.  
  69.     if (/\\subsubsection{(.*)}/) {
  70.       &dosubs($line);
  71.       print "\t\t$line\n";
  72.       next;
  73.     }
  74. }
  75.  
  76. sub dosubs {
  77.  
  78.   ($line = $1) =~ s/\\#/#/;
  79.   $line =~ s/ANYOUTRAGEOUSSTRING/s--s/;
  80.  
  81. }
  82.  
  83.  
  84.  
  85. >Plumbers Motto:  A flush beats a full house.
  86.  
  87. Really.
  88.  
  89. >--------------------------------------------------------------
  90. >Jim Harkins                         [ucsd|uunet]!pacdata!jim
  91. >Pacific Data Products               jim@pacdata.com
  92. >--------------------------------------------------------------
  93.  
  94. ps: Jim, you will undoubtedly see 47 other approaches to this come rolling
  95. off the net soon. May I suggest you include ALL of them in your class, and
  96. thereby illustrate the Perl motto?
  97.  
  98.      There is more than one way to do it!
  99.  
  100.  
  101.  
  102.  
  103.  
  104.