in reply to Re:{4} how do I line-wrap while copying to stdout?
in thread how do I line-wrap while copying to stdout?

Note that neither of these solutions wraps the text properly, because neither one accounts for the newlines already present in the text.

Suppose you were wrapping the following at 10 characters:

abcdefghijklm nopqrstuvwxyz
The proper result is:
abcdefghij klm nopqrstuvw xyz
However, the solutions in the Benchmark will produce:
abcdefghij klm nopqrs tuvwxyz
The regex solution is easy to fix: print DUMP map "$_\n", $a=~/(.{1,80})/g; The substr() solution requires more work to get right, such as splitting on newlines and wrapping each line separately, or sticking any partial lines back onto to the beginning of the string after each substr().

Replies are listed 'Best First'.
Re:{6} how do I line-wrap while copying to stdout?
by jeroenes (Priest) on Apr 21, 2001 at 02:15 UTC
    Look at the root node. There were the lines coming in one by one, but some of them too long. The b'marked routines all work on one string. I took a file for it because that makes up a nice long string. Somewhere deaper i just took $str='a'x 1e7. Boils down to the same.

    Jeroen
    "We are not alone"(FZ)