#!/usr/bin/perl -w # # $Id: numpara,v 1.1 2007/11/21 00:31:29 vogelke Exp $ # # Number paragraphs using line numbers. # Intended for offline review of a document. use strict; my $startcol = 74; my $prev = 'full'; my $line = 0; my $blanks = ' ' x $startcol; my $suffix = ''; while (<>) { chomp; $line++; $suffix = " ($line)"; # if the current line is empty, print a newline and # make a note of it. if (/^\s*$/) { print "\n"; $prev = 'empty'; } # if the current line is NOT empty but the previous line was, # we're starting a new paragraph. Put the paragraph number in # the starting column if possible, or just append it if not. else { if ($prev eq "empty" || $line == 1) { if (length($_) < $startcol - 1) { $_ .= $blanks; substr($_, $startcol) = $suffix; } else { $_ .= $suffix; } } print "$_\n"; $prev = 'full'; } } exit(0);