split() in perl
How to divide text into sentences. In my opinion, I should use split() and print them, but I donˇt now have. I am just started learning Perl.
My text
A block of text is a stack of line boxes. In the case of 'left', 'right' and 'center', this property specifies how the inline-lev开发者_StackOverflow社区el boxes within each line box align with respect to the line box's left and right sides; alignment is not with respect to the viewport. In the case of 'justify', this property specifies that the inline-level boxes are to be made flush with both sides of the line box if possible, by expanding or contracting the contents of inline boxes, else aligned as for the initial value. See also 'letter-spacing' and 'word-spacing'.
If this isn't actually homework, I would just use one of the CPAN modules which handle this, say Lingua::Sentence which seems to be under active development.
One way to do it is using split
in combination with look-behind.
perl -nlwe 'print for split /(?<=\S[.!?])\s+/' < data.txt
This works for your sample data.
What you want to do here is eliminate the space separating sentences. An end of sentence is defined as one of .!?
preceded by a non-whitespace character. Tweak as desired.
try
$paragraph = "Text. Text";
@sentences = split(/\./, $paragraph);
print @sentences;
精彩评论