Hello lobs,
Where possible, it’s generally better to use an existing module than to re-invent the wheel. In this case, there are modules on such as Text::Sentence that do most of the work for you:
use strict; use warnings; use Text::Sentence qw( split_sentences ); my $sent = 'George Washington'; my $doc = do { local $/; <DATA>; }; my @sentences = split_sentences($doc); for (@sentences) { if (/^'?$sent'?\s+(?:is|was)/) { print "FOUND:\n$_\n"; last; } } __DATA__ The quick brown fox jumped over the unfortunate dog. 'George Washington' was the first President of the United States, the +Commander-in-Chief of the Continental Army during the American Revolu +tionary War, and one of the Founding Fathers of the United States. He + presided over the convention that drafted the current United States +Constitution and during his lifetime was called the "father of his co +untry". Widely admired for his strong leadership qualities, Washington was una +nimously elected president in the first two national elections. He ov +ersaw the creation of a strong, well-financed national government tha +t maintained neutrality in the French Revolutionary Wars, suppressed +the Whiskey Rebellion, and won acceptance among Americans of all type +s.[5] Washington's incumbency established many precedents, still in u +se today, such as the cabinet system, the inaugural address, and the +title Mr. President.[6][7] His retirement from office after two terms + established a tradition that lasted until 1940, when Franklin Delano + Roosevelt won an unprecedented third term. The 22nd Amendment (1951) + now limits the president to two elected terms.
Output:
14:11 >perl 1601_SoPW.pl FOUND: 'George Washington' was the first President of the United States, the +Commander-in-Chief of the Continental Army during the American Revolu +tionary War, and one of the Founding Fathers of the United States. 14:11 >
Hope that helps,
| Athanasius <°(((>< contra mundum | Iustus alius egestas vitae, eros Piratica, |
In reply to Re: Regular expression for Wikipedia Module
by Athanasius
in thread Regular expresión for Wikipedia Module
by lobs
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |