S
Sandman
I've searched the docs, but I can't seem to get it right... I want to split a
paragraph into sentences, but this doesn't work:
#!/usr/bin/perl
use strict;
use warnings;
my $string = "This is a sentence. This is also a sentence. This as well, right?
Yes, it is!";
my @list = split / ?(?=[\.\?\!])/, $string;
foreach (@list){
print "$_\n";
}
__END__
This is a sentence
.. This is also a sentence
.. This as well, right
? Yes, it is
!
The delimiter is kept, but to the wrong item - how do I keep it attached to the
correct item?
Or is there a special var that keeps the matched delimiter in a split()
operation, so I could do something like this:
#!/usr/bin/perl
use strict;
use warnings;
my $string = "This is a sentence. This is also a sentence. This as well, right?
Yes, it is!";
my @list = split /[\.\?\!] /, $string;
foreach (@list){
print "$_$SPECIALVARIABLE\n";
}
As you may have understood, the wanted output is:
This is a sentence.
This is also a sentence.
This as well, right?
Yes, it is!
paragraph into sentences, but this doesn't work:
#!/usr/bin/perl
use strict;
use warnings;
my $string = "This is a sentence. This is also a sentence. This as well, right?
Yes, it is!";
my @list = split / ?(?=[\.\?\!])/, $string;
foreach (@list){
print "$_\n";
}
__END__
This is a sentence
.. This is also a sentence
.. This as well, right
? Yes, it is
!
The delimiter is kept, but to the wrong item - how do I keep it attached to the
correct item?
Or is there a special var that keeps the matched delimiter in a split()
operation, so I could do something like this:
#!/usr/bin/perl
use strict;
use warnings;
my $string = "This is a sentence. This is also a sentence. This as well, right?
Yes, it is!";
my @list = split /[\.\?\!] /, $string;
foreach (@list){
print "$_$SPECIALVARIABLE\n";
}
As you may have understood, the wanted output is:
This is a sentence.
This is also a sentence.
This as well, right?
Yes, it is!