#!/usr/bin/perl # Make a text file have a maximum line width. Arguements are: # - max width # - indent on broken line # todo: doesn't deal with tabs, or broken line indent, or forced newlines... use strict; my($word, $indent, $intab, $count); for($count = 0; $count < $ARGV[1]; $count++){ $intab = "$intab "; } $indent = 0; while(){ foreach $word (split(/ /, $_)){ if(($indent + length($word)) > $ARGV[0]){ print "\r\n$intab"; $indent = length($intab); } if($word =~ /(.*)[\r]*\n(.*)/){ $indent = length($2); print "$1\r\n$2"; } else{ $indent += length($word); print "$word "; } } }