I'd probably do that more like this:

#!/usr/local/bin/perl use strict; my @phrases; my $conj= '\b(?:than|that|which|who|and|but)\b'; while( <DATA> ) { chomp; while( 140 < length($_) ) { if( s/^(.{1,139}\W)\s+// # Break after punctuation || s/^(.{1,136}$conj\S*)\s+// # Break after conjunction || s/^(.{1,139}\S)\s+// # Break on space ) { push @phrases, $1; } elsif( s/^(.{139})// ) { # Break in word push @phrases, "$1-"; } else { die "Impossible!"; } } push @phrases, $_; } print $_, $/ for @phrases; __DATA__ The Golden Bowl. The Prince had always liked his London, when it had come to him; he wa +s one of the modern Romans who find by the Thames a more convincing i +mage of the truth of the ancient state than any they have left by the + Tiber. Brought up on the legend of the City to which the world paid tribute, +he recognised in the present London much more than in contemporary Ro +me the real dimensions of such a case. If it was a question of an Imperium, he said to himself, and if one wi +shed, as a Roman, to recover a little the sense of that, the place to + do so was on London Bridge, or even, on a fine afternoon in May, at +Hyde Park Corner. It was not indeed to either of those places that these grounds of his +predilection, after all sufficiently vague, had, at the moment we are + concerned with him, guided his steps; he had strayed, simply enough, + into Bond Street, where his imagination, working at comparatively sh +ort range, caused him now and then to stop before a window in which o +bjects massive and lumpish, in silver and gold, in the forms to which + precious stones contribute, or in leather, steel, brass, applied to +a hundred uses and abuses, were as tumbled together as if, in the ins +olence of the Empire, they had been the loot of far-off victories. The young man's movements, however, betrayed no consistency of attenti +on--not even, for that matter, when one of his arrests had proceeded +from possibilities in faces shaded, as they passed him on the pavemen +t, by huge beribboned hats, or more delicately tinted still under the + tense silk of parasols held at perverse angles in waiting victorias. And the Prince's undirected thought was not a little symptomatic, sinc +e, though the turn of the season had come and the flush of the street +s begun to fade, the possibilities of faces, on the August afternoon, + were still one of the notes of the scene. He was too restless--that was the fact--for any concentration, and the + last idea that would just now have occurred to him in any connection + was the idea of pursuit. Bork bork bork bork bork bork bork bork bork bork bork bork bork bork +bork bork bork bork bork bork bork bork bork bork bork bork bork bork + bork bork bork bork bork bork bork bork bork.

Producing:

The Golden Bowl. The Prince had always liked his London, when it had come to him; he was one of the modern Romans who find by the Thames a more convinci +ng image of the truth of the ancient state than any they have left by the Tiber. Brought up on the legend of the City to which the world paid tribute, he recognised in the present London much more than in contemporary Rom +e the real dimensions of such a case. If it was a question of an Imperium, he said to himself, and if one wi +shed, as a Roman, to recover a little the sense of that, the place to do so was on London Bridge, or even, on a fine afternoon +in May, at Hyde Park Corner. It was not indeed to either of those places that these grounds of his +predilection, after all sufficiently vague, had, at the moment we are concerned with him, guided his steps; he had stra +yed, simply enough, into Bond Street, where his imagination, working at comparatively short range, caused him now and then to stop +before a window in which objects massive and lumpish, in silver and gold, in the forms to which precious stones contribute, +or in leather, steel, brass, applied to a hundred uses and abuses, were as tumbled together as if, in the insolence of the Empire, they h +ad been the loot of far-off victories. The young man's movements, however, betrayed no consistency of attenti +on--not even, for that matter, when one of his arrests had proceeded from possibilities in faces shad +ed, as they passed him on the pavement, by huge beribboned hats, or more delicately tinted still under the tense silk of parasols held +at perverse angles in waiting victorias. And the Prince's undirected thought was not a little symptomatic, sinc +e, though the turn of the season had come and the flush of the streets be +gun to fade, the possibilities of faces, on the August afternoon, were still one of the notes of the scene. He was too restless--that was the fact--for any concentration, and the last idea that would just now have occurred to him in any conn +ection was the idea of pursuit. Bork bork bork bork bork bork bork bork bork bork bork bork bork bork +bork bork bork bork bork bork bork bork bork bork bork bork bork bork bork bork bork bork bork bork bork bork bork.

Or, cutting the max width in half, produces the following output that fits much better in my brower:

The Golden Bowl. The Prince had always liked his London, when it had come to him; he was one of the modern Romans who find by the Thames a more convincing image of the truth of the ancient state than any they have left by the Tiber. Brought up on the legend of the City to which the world paid tribute, he recognised in the present London much more than in contemporary Rome the real dimensions of such a case. If it was a question of an Imperium, he said to himself, and if one wished, as a Roman, to recover a little the sense of that, the place to do so was on London Bridge, or even, on a fine afternoon in May, at Hyde Park Corner. It was not indeed to either of those places that these grounds of his predilection, after all sufficiently vague, had, at the moment we are concerned with him, guided his steps; he had strayed, simply enough, into Bond Street, where his imagination, working at comparatively short range, caused him now and then to stop before a window in which objects massive and lumpish, in silver and gold, in the forms to which precious stones contribute, or in leather, steel, brass, applied to a hundred uses and abuses, were as tumbled together as if, in the insolence of the Empire, they had been the loot of far-off victories. The young man's movements, however, betrayed no consistency of attention--not even, for that matter, when one of his arrests had proceeded from possibilities in faces shaded, as they passed him on the pavement, by huge beribboned hats, or more delicately tinted still under the tense silk of parasols held at perverse angles in waiting victorias. And the Prince's undirected thought was not a little symptomatic, since, though the turn of the season had come and the flush of the streets begun to fade, the possibilities of faces, on the August afternoon, were still one of the notes of the scene. He was too restless--that was the fact--for any concentration, and the last idea that would just now have occurred to him in any connection was the idea of pursuit. Bork bork bork bork bork bork bork bork bork bork bork bork bork bork bork bork bork bork bork bork bork bork bork bork bork bork bork bork bork bork bork bork bork bork bork bork bork.

- tye        


In reply to Re: Towards a Text::Wrap::Meaningful? (simpler) by tye
in thread Towards a Text::Wrap::Meaningful? by Cody Fendant

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.