in reply to Using punctuation to split a text
use warnings; use strict; my $SPACER = "\n\n"; while (my $line = <DATA>) { $line =~ s|^\s+||; ## trim leading whitespace $line =~ s|\s+$||; ## trim trailing whitespace $line =~ s|([.?!]+)\s*|$1$SPACER|g; ## break at [.?!] $line =~ s|([a-z])([A-Z])|$1$SPACER$2|g; ## break at camelCase print $line . $SPACER; }
prints:__DATA__ The Tell-Tale LiverEdgar Allen MyselfFALSE! nervous I had been and am; + but am I mad? The disease had sharpened, not destroyed my senses.. +. Above all was the sense of hearing acute.How then am I mad?! + Hearken! and observe how calmly, I can tell you the story.
The Tell-Tale Liver Edgar Allen Myself FALSE! nervous I had been and am; but am I mad? The disease had sharpened, not destroyed my senses... Above all was the sense of hearing acute. How then am I mad?! Hearken! and observe how calmly, I can tell you the story.
|
|---|