Getting rid of punctuation in chunked strings

S

Stevee

Hi all.

Apologies if this is a newbie question, but I am new!

I am reading in a string, splitting it into chunks on whitespace and
placing the values in an array which I then process further to match.
I am having problems because some of the matches are not working
because the chunking gives things like

"martin, "

or

"martin. "

i.e there is a comma or full stop as the end of the chunk.

Any ideas how to remove the punctuation before I put the values in the
array to match?

Thanks in advance.
 
A

A. Sinan Unur

Apologies if this is a newbie question, but I am new!

I am reading in a string, splitting it into chunks on whitespace and
placing the values in an array which I then process further to match.
I am having problems because some of the matches are not working
because the chunking gives things like

"martin, "

or

"martin. "

i.e there is a comma or full stop as the end of the chunk.

Any ideas how to remove the punctuation before I put the values in the
array to match?

Use split.

#!/usr/bin/perl

use strict;
use warnings;

my $str = <<EO_TEXT;
I, being the obnoxious person that I am, will ask
Mr. Steeve to please read the posting guidelines,
given that he is new to this group.
EO_TEXT

my @words = split /[[:punct:]]?\s+[[:punct:]]?/, $str;

{
local $" = '#';
print "@words\n";
}
__END__

D:\Home\asu1\UseNet\clpmisc> tt
I#being#the#obnoxious#person#that#I#am#will#ask#Mr#Steeve#to#please#read
#the#posting#guidelines#given#that#he#is#new#to#this#group
 
A

Anno Siegel

Stevee said:
Hi all.

Apologies if this is a newbie question, but I am new!

I am reading in a string, splitting it into chunks on whitespace and
placing the values in an array which I then process further to match.
I am having problems because some of the matches are not working
because the chunking gives things like

"martin, "

or

"martin. "

No, it doesn't, not if you split on white space. Your examples
*contain* white space. Show your code so it is clear what you
are doing.
i.e there is a comma or full stop as the end of the chunk.

Any ideas how to remove the punctuation before I put the values in the
array to match?

You could split on a combination of white space and punctuation:

my $sentence = "Martin, Martin. O'Brien!";
print "$_\n" for split /[[:space:][:punct:]]+/, $sentence;

....or maybe not. You need to define what is punctuation and what
isn't.

Anno
 
R

robic0

Hi all.

Apologies if this is a newbie question, but I am new!

I am reading in a string, splitting it into chunks on whitespace and
placing the values in an array which I then process further to match.
I am having problems because some of the matches are not working
because the chunking gives things like

"martin, "

or

"martin. "

i.e there is a comma or full stop as the end of the chunk.

Any ideas how to remove the punctuation before I put the values in the
array to match?

Thanks in advance.
Nobody knows what punctuation is. Search the internet for punctuation.
When you can define it, then your %99 there.
(Notice I didn't post any bullshit code like the other slackers?)
 
R

robic0

Nobody knows what punctuation is. Search the internet for punctuation.
When you can define it, then your %99 there.
(Notice I didn't post any bullshit code like the other slackers?)
Time for a gut check upload of the King James Bible
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top