Fun. As a one-liner:
perl -wlne"printf qq[\t'%s'\n], join qq['+\n\t'], m[(.{1,34}(?: |$)|.{34})] +g" junk.txt 'Here is one big long string which '+ 'needs to have some formatting done '+ 'to it before I can use it for '+ 'input in a separate program.' 'I would like it to be formatted '+ 'exactly as follows (except for the '+ 'exact line length)'
Or with a configurable line length
#! perl -slw use strict; for my $n ( 4 , 34, 70 ) { print "\n$n"; my $pos = tell DATA; while( <DATA> ) { chomp; printf "\t'%s'\n", join "'+\n\t'", m[(.{1,$n}(?: |$)|.{$n})]g; } seek DATA, $pos, 0; } __DATA__ Here is one big long string which needs to have some formatting done t +o it before I can use it for input in a separate program. I would like it to be formatted exactly as follows (except for the exa +ct line length)
P:\test>junk 4 'Here '+ 'is '+ 'one '+ 'big '+ 'long '+ 'stri'+ 'ng '+ 'whic'+ 'h '+ 'need'+ 's to '+ 'have '+ 'some '+ 'form'+ 'atti'+ 'ng '+ 'done '+ 'to '+ 'it '+ 'befo'+ 're I '+ 'can '+ 'use '+ 'it '+ 'for '+ 'inpu'+ 't in '+ 'a '+ 'sepa'+ 'rate '+ 'prog'+ 'ram.' 'I '+ 'woul'+ 'd '+ 'like '+ 'it '+ 'to '+ 'be '+ 'form'+ 'atte'+ 'd '+ 'exac'+ 'tly '+ 'as '+ 'foll'+ 'ows '+ '(exc'+ 'ept '+ 'for '+ 'the '+ 'exac'+ 't '+ 'line '+ 'leng'+ 'th)' 34 'Here is one big long string which '+ 'needs to have some formatting done '+ 'to it before I can use it for '+ 'input in a separate program.' 'I would like it to be formatted '+ 'exactly as follows (except for the '+ 'exact line length)' 70 'Here is one big long string which needs to have some formatti +ng done '+ 'to it before I can use it for input in a separate program.' 'I would like it to be formatted exactly as follows (except fo +r the '+ 'exact line length)'
In reply to Re: Text::Format Module q
by BrowserUk
in thread Text::Format Module q
by jriggs420
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |