home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.perl
- Path: sparky!uunet!srvr1.engin.umich.edu!batcomputer!cornell!uw-beaver!fluke!inc
- From: inc@tc.fluke.COM (Gary Benson)
- Subject: Re: Short sample program needed
- Message-ID: <1993Jan21.184849.13619@tc.fluke.COM>
- Organization: John Fluke Mfg. Co., Inc., Everett, WA
- References: <1993Jan18.214646.2924@pacdata.uucp>
- Date: Thu, 21 Jan 1993 18:48:49 GMT
- Lines: 93
-
- In article <1993Jan18.214646.2924@pacdata.uucp> jimh@pacdata.com (Jim Harkins) writes:
- >I should say right off the bat that I don't know perl. With that out of the
- >way, I need a short sample perl program that will convert TeX input into
- >a syllabus. For example, given the input:
- >
- >\section{Online documentation}
- > \subsection{Unix rule \#1 - RTFM}
- > \begin{itemize}
- > \item Online manual (man) pages
- > \item Readme files (e.g. /usr/local/gnu-src/README)
- > \item Large manuals (e.g.
- > /usr/local/gnu-src/g960/doc/misc/gcc/gcc-user.ms, over 200 pages of
- > documentation on gcc.
- > \item Look for files ending with .ms, .man, .tex.
- > \end{itemize}
- >
- > \subsubsection{Scooby doobie doo}
- > .....
- > \subsection{Man is your friend}
- >
- >I need the output
- >
- >Online documentation
- > Unix rule #1 - RTFM
- > Scooby doobie doo
- > Man is your friend
- >
- >All I care about are section, subsection, and subsubsections. I can ignore
- >little stuff like the backslash in front of the #.
-
-
- This is very easy in perl, one of the first types of things that many people
- first use perl to do: a good choice for an introductory class, in my
- opinion!. My little attempt below meets your requirements for not using
- trickery and for a straightforward approach to just doing the job. I have
- included one "feature", though: a subroutine to do any kind of cleaning up
- you might like, for example that ugly \# thing.
-
- Here's my try:
-
- #! /usr/local/perl -d
-
- $debug if $d;
- print "$0: A Definite Improvement over AWK!!\n" if $debug;
-
- while (<>) {
-
- if (/\\section{(.*)}/) {
- &dosubs();
- print "\n$line\n";
- next;
- }
- if (/\\subsection{(.*)}/) {
- &dosubs($line);
- print "\t$line\n";
- next;
- }
-
- if (/\\subsubsection{(.*)}/) {
- &dosubs($line);
- print "\t\t$line\n";
- next;
- }
- }
-
- sub dosubs {
-
- ($line = $1) =~ s/\\#/#/;
- $line =~ s/ANYOUTRAGEOUSSTRING/s--s/;
-
- }
-
-
-
- >Plumbers Motto: A flush beats a full house.
-
- Really.
-
- >--------------------------------------------------------------
- >Jim Harkins [ucsd|uunet]!pacdata!jim
- >Pacific Data Products jim@pacdata.com
- >--------------------------------------------------------------
-
- ps: Jim, you will undoubtedly see 47 other approaches to this come rolling
- off the net soon. May I suggest you include ALL of them in your class, and
- thereby illustrate the Perl motto?
-
- There is more than one way to do it!
-
-
-
-
-
-