in reply to Using punctuation to split a text

The following regex using lookback and look ahead assertions gets pretty close. However I don't think there is a way to distinguish between the two places where "mad?" is used except by explicit special cases.

use strict; use warnings; my $str = <<DATA; The Tell-Tale HeartEdgar Allen PoeTRUE! nervous, very, very dreadfully + nervous I had been and am; but why WILL you say that I am mad? The d +isease had sharpened my senses, not destroyed, not dulled them. Above + all was the sense of hearing acute. I heard all things in the heaven + and in the earth. I heard many things in hell. How then am I mad? He +arken! and observe how healthily, how calmly, I can tell you the whol +e story. DATA $str =~ s/(?<=[a-z])(?=[A-Z])|(?<=[?!.] )(?![a-z])/\n/g; print $str;

Prints:

The Tell-Tale Heart Edgar Allen Poe TRUE! nervous, very, very dreadfully nervous I had been and am; but wh +y WILL you say that I am mad? The disease had sharpened my senses, not destroyed, not dulled them. Above all was the sense of hearing acute. I heard all things in the heaven and in the earth. I heard many things in hell. How then am I mad? Hearken! and observe how healthily, how calmly, I can tell you the who +le story.

DWIM is Perl's answer to Gödel

Replies are listed 'Best First'.
Re^2: Using punctuation to split a text
by UrbanHick (Sexton) on Nov 04, 2006 at 09:53 UTC

    Thank you for your time and response.

    Actually single words are acceptable. I am actually cutting up larger files to be used by an ESL teaching program.

    Thanks,

    UH