On 14/11/2010 19:04, Zachary Brooks wrote:
What happened when I used the code --
$hello =~ s/^(.+)$/<s>\1<\/s>/gis;
-- is that is properly marked<s> and the beginning of the sentence and</s>
at the end of the sentence, but then it only worked for one sentence.
Any suggestions on getting<s> to appear at the beginning of every sentence
and</s> to appear at the end of every sentence for more than one sentence?
You must think carefully about what constitutes a 'sentence'. A string
starting with a capital letter and ending with a full stop is the most
basic definition, but is unlikely to be sufficient for your purposes
unless your data is very simple.
The program below uses this definition to enclose all 'sentences' in a
multi-line string in <s> tags. I hope it helps you to get started.
- Rob
use strict;
use warnings;
my $text = "
This is some sample text. It has
three sentences, all beginning with
a capital letter and ending with a full
stop. Proper recognition of a 'sentence'
could get extremely complicated.";
$text =~ s|([A-Z].*?\.)|<s>$1</s>|gs;
print $text;
__END__
**OUTPUT**
<s>This is some sample text.</s> <s>It has
three sentences, all beginning with
a capital letter and ending with a full
stop.</s> <s>Proper recognition of a 'sentence'
could get extremely complicated.</s>
--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/