in reply to Retreaving N first sentences from text.

Uhhh.. if you know that all sentences are separated by the '.', then why not do something like:
sub get_nsentences { my ($source_text, $n) = @_; my @sentences = split /\.\s*/, $source_text; $ret_text = (join '.', @sentences[0..$n-1]) . '.'; return $ret_text; }

------
We are the carpenters and bricklayers of the Information Age.

Don't go borrowing trouble. For programmers, this means Worry only about what you need to implement.

Replies are listed 'Best First'.
Re: Re: Retrieving N first sentences from text.
by boo_radley (Parson) on Dec 15, 2001 at 03:55 UTC
    broken : She said "I believe this will be the winter of my discontent. Then again, I may drink some egg-nog. Who knows?".
    How many sentences there?
Re: Re: Retreaving N first sentences from text.
by blakem (Monsignor) on Dec 15, 2001 at 03:59 UTC
    You could use the /g regex modifier to overcome the 'only periods' assumption....
    sub get_nsentences { my $text = shift; my $count = shift || 1; join '', ($text =~ /.*?[\.!?]/sg)[0..$count-1] }
    This keeps the punctuation with the "sentence" so you don't have to keep track of what it was.... i.e. you can join with '', not with '.'

    -Blake