aaron_baugher++ has solved the problem. But as to the regex, why reinvent the wheel when has modules to identify English sentences? For example, Lingua::EN::Sentence contains a get_sentences function which seems to do nicely:
#! perl use strict; use warnings; use Lingua::EN::Sentence 'get_sentences'; local $/ = ''; # Paragraph mode my $sentence_count = 0; my $paragraph_count = 0; my @paragraphs; while (my $paragraph = <DATA>) { my $sentences = get_sentences($paragraph); @$sentences = map { '<s>' . $_ . '</s>' } @$sentences; push @paragraphs, "<p>\n\t" . join("\n\t", @$sentences) . "\n</p>\ +n"; $sentence_count += scalar @$sentences; ++$paragraph_count; } print "\nTotal sentences: $sentence_count\n"; print "Total paragraphs: $paragraph_count\n"; print for @paragraphs; __DATA__ But the truth is that in the short run, markets can occasionally be pu +shed, especially when so many decisions to buy or sell are keyed off +what everyone else in the market is doing. Chain reactions are not mu +ch harder to start (in fact, given how quickly price moves get notice +d, they may be easier) than they were 70 years ago. This is a sentence containing ... an ellipsis. "Well, OK then," he sai +d, "but let's not get ahead of ourselves." And so to bed... And in this sentence, dialogue is delimited with single quotes. 'Well, + OK then,' he said, 'but let's not get ahead of ourselves.' And the h +euristic still works!
Output:
12:59 >perl 741a_SoPW.pl Total sentences: 8 Total paragraphs: 3 <p> <s>But the truth is that in the short run, markets can occasio +nally be pushed, especially when so many decisions to buy or sell are + keyed off what every one else in the market is doing.</s> <s>Chain reactions are not much harder to start (in fact, give +n how quickly price moves get noticed, they may be easier) than they +were 70 years ago.</s> </p> <p> <s>This is a sentence containing ... an ellipsis.</s> <s>"Well, OK then," he said, "but let's not get ahead of ourse +lves."</s> <s>And so to bed...</s> </p> <p> <s>And in this sentence, dialogue is delimited with single quo +tes.</s> <s>'Well, OK then,' he said, 'but let's not get ahead of ourse +lves.'</s> <s>And the heuristic still works!</s> </p> 12:59 >
Hope that helps,
| Athanasius <°(((>< contra mundum | Iustus alius egestas vitae, eros Piratica, |
In reply to Re^5: How to match regex over multiline file
by Athanasius
in thread How to match regex over multiline file
by kyaloupe
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |