#! c:/perl/bin/perl # # Filename: endnote.pl # Author: Eric Pement - pemente [=at=] northpark.edu # Version: 1.1 # Date: 24 Mar 2002 # Purpose: To convert in-text notes and references to endnotes # Requires: Perl5; blank lines between paragraphs of input file # Usage: perl endnote.pl yourfile.txt [ >output.txt] # or # perl -s endnote.pl -start=N yourfile.txt [ >output.txt] # where N is a positive integer. # Output: Plain ASCII text. Can be modified for HTML. # See also: ENDNOTE.TXT, which further explains usage and application. # To do: check for mismatched "[[" and "]]" braces. # # Credits: The idea for this endnote system was borrowed from "wsNOTE" # by Eric Meyer, a 1988 MS-DOS utility for managing footnotes # in WordStar files. His program offered many extra features. $a=$b= (defined $start ? start - 1: 0); $c = ""; # set global variables while (<>) { chomp; if ( /^\[\[$/ .. /^]]$/ ) { # if between [[ and ]] markers.. next if /^\[\[$/; # .. skip the [[ marker, s/.*// if /^]]$/; # .. change the ]] marker to a blank line, s/##(?=\.)/++$a/ge; # .. increment each '##.' to next $a., $c = $c . $_ . "\n"; # .. append the line to $c string variable. } else { # if not in the note section.. s/##(?=])/++$b/ge; # .. just increment each '##' to next $b, # NOTE: technically, the regex above ought to match /\[##]/, but Perl # is giving me fits about this 4-char string. I'm settling for a 3-char # string, but it's really an temp solution till I learn more Perl. print $_ . "\n"; # .. and print that line. } } if ( $a != $b ) { # error-checking. Are $a and $b equal? print "\a\a\n\n\n================\n WARNING!\n================\n"; print "Body text numbers and Endnote numbers don't match!\n"; print "The Endnote section will not be printed.\n\n\n"; } else { # Add endnotes if body text looks okay print "\n-----------\nENDNOTES:\n\n", $c , "[end of file]\n"; } #---end of script---