hacker has asked for the wisdom of the Perl Monks concerning the following question:
use strict; use Text::Autoformat; open(PGW, "<3ward10.txt") or die $!; while (<PGW>) { my $formatted = autoformat $_, {justify =>'left', left =>2, right =>60, all =>1, }; print $formatted; }
So far, so good.. you'd expect it to take the input file, 3ward10.txt, rewrap the text found to 58 columns (+2), and print it to STDOUT. It doesn't. I looked into Text::Wrap, Text::Correct and others without success.
The other odd thing about this, is that when the original file is left intact, with the ^M characters at the end of each line, the above code "works" (though doesn't wrap or reformat the text), but if I strip out the ^M characters (s,\cM,,g), the above code dies on the third line of the file (a blank line). Removing the line then causes it to barf on the next blank line, and so on (try it yourself, you'll see what I mean).
Can Text::Autoformat not deal with blank lines in a paragraph? That would seem... odd. I also notice I can't seem to stuff the file contents (via the handle, PGW) into an array, and feed that to Text::Autoformat (my @data = <PGW>;) What am I missing here? Why doesn't ::Autoformat actually do as advertised? Some glaring error on my part?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Text::Autoformat... doesn't.
by converter (Priest) on Oct 27, 2002 at 08:33 UTC | |
|
Re: Text::Autoformat... doesn't.
by grantm (Parson) on Oct 27, 2002 at 07:15 UTC | |
|
Re: Text::Autoformat... doesn't.
by Anonymous Monk on Oct 27, 2002 at 07:44 UTC |