On 10/8/09 Thu  Oct 8, 2009  3:56 PM, "Harry Putnam" <rea...@newsguy.com>
scribbled:

> Shlomi Fish <shlo...@iglu.org.il> writes:
> 
>> Hi Harry!
> 
> [...]
> 
>>> 
>>> I want to catch those long lines and format them like one might format
>>> a news/mail message... wrapped at column 72 or so but also indented
>>> whatever spcs looks good.
>>> 
>>> I looked at perldoc -f format but that says its about pictures and
>>> doesn't appear to be intended to format text.
>>> 
>> 
>> Have you tried http://search.cpan.org/dist/Perl6-Form/ ? Or maybe:
>> 
>> http://search.cpan.org/dist/Text-Tabs+Wrap/
> 
> Those do look tempting, especially the first, but both seem a little
> heavy handed for what I need... And might take me a good bit to figure
> out how to use them....I may just look for a specific line and
> torture it till it looks like I want it too.
> 
> At this point my input will only include one recalcitrant line where
> there is a problem... but it makes the tool whos' output I want to fix
> put out all lines to match that long one...
> 
> Where all but one line follow this:
> some  setting=word        setting=word         setting=word
> 
> -------        ---------       ---=---       ---------      --------
> Adding the bad line does this:
> some  setting=word         <<lots of extra space now  here>>
> setting=word         setting=word
> some  OtherSetting=a whole big long line of never ending words like this one
> causing the program to ouput       setting=word         setting=word
> -------        ---------       ---=---       ---------      --------
> 
> So the line with OtherSetting is causing all lines to be output with
> space to accommodate the long setting.
> 
> The tool provided by OS does that on its own so I want to fix its ouput...
> 
> I guess just watching for that line.. and manually folding it with
> perl will do what I want.  If I can figure out how to clip out the
> extra space now included in all other lines.
> 

You might try splitting the line on whitespace, extracting the first two and
last two elements, then joining the remainder back with a space. You can
then test the length of the middle string for excessive length and print or
trim accordingly. This will concatenate any extra spaces in the middle
string.

This only works if the first two and last two fields contain no spaces.



-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to