#! perl5 # # despc.pl Daniel Brockman 20030217 removes excess spaces, wraps at 60 char # # Usage: perl -- despc.pl < inputfile > outputfile ################################################ # The author grants permission to use for any # # purpose, including copying and modification, # # provided the user acknowledges the author by # # name. # # -- Daniel Brockman, author, 20031220 # ################################################ $wrap=60; $prev=1; # 0=space, 1=nonspace, 2=prev part of continued line while ($line=<>) { # BIG LOOP $line=~s/[ \t]+\n/\n/g ; # remove trailing white space $linx=$line ; $linx=~s/[ \t\n]+//g ; if($linx=~m/^$/){ # it's a blank line if($prev==0) {next} # prev line blank? go on to next. print "$line"; # otherwise, print it $prev=0; # note, it was blank next; # and go on }else{ # nonblank while(length($line)>0){ # while some line remains if(length($line)<$wrap){ print($line); $prev=1; last; # escape from loop }else{ $break=$wrap-1; for($i=$break;$i>0;$i--){ if(substr($line,$i,1) eq ' '){ $break=$i; last; # leave loop } } $linx=substr($line,$break+1); # from the break to the end of the line substr($line,$break+1)="" ; print("$line\n"); $prev=2; # continue $line=$linx ; $line=~s/^[ \t]+// ; # remove leading blanks } } # end while some line remains } # end if nonblank } # end while BIG LOOP #