Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > Getting rid of punctuation in chunked strings

Reply
Thread Tools

Getting rid of punctuation in chunked strings

 
 
Stevee
Guest
Posts: n/a
 
      12-09-2005
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.

 
Reply With Quote
 
 
 
 
A. Sinan Unur
Guest
Posts: n/a
 
      12-09-2005
"Stevee" <(E-Mail Removed)> wrote in
news:(E-Mail Removed) oups.com:

> 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 /[[unct:]]?\s+[[unct:]]?/, $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#th is#group
--
A. Sinan Unur <(E-Mail Removed)>
(reverse each component and remove .invalid for email address)

comp.lang.perl.misc guidelines on the WWW:
http://mail.augustmail.com/~tadmc/cl...uidelines.html

 
Reply With Quote
 
 
 
 
Anno Siegel
Guest
Posts: n/a
 
      12-09-2005
Stevee <(E-Mail Removed)> wrote in comp.lang.perl.misc:
> 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:][unct:]]+/, $sentence;

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

Anno
--
If you want to post a followup via groups.google.com, don't use
the broken "Reply" link at the bottom of the article. Click on
"show options" at the top of the article, then click on the
"Reply" at the bottom of the article headers.
 
Reply With Quote
 
robic0
Guest
Posts: n/a
 
      12-10-2005
On 9 Dec 2005 04:51:21 -0800, "Stevee"
<(E-Mail Removed)> wrote:

>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?)

 
Reply With Quote
 
robic0
Guest
Posts: n/a
 
      12-10-2005
On Fri, 09 Dec 2005 22:22:58 -0800, robic0 wrote:

>On 9 Dec 2005 04:51:21 -0800, "Stevee"
><(E-Mail Removed)> wrote:
>
>>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?)

Time for a gut check upload of the King James Bible

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Strings, Strings and Damned Strings Ben C Programming 14 06-24-2006 05:09 AM
Chunked GZIP processing using Java Sockets aztechnology@gmail.com Java 10 03-29-2006 07:26 AM
httplib raises ValueError reading chunked content philip20060308@gmail.com Python 0 03-08-2006 11:21 PM
HttpURLConnection receiving chunked encoded responses d_cymbal@hotmail.com Java 0 04-13-2005 09:02 PM
transfer encoding: chunked CW ASP .Net 0 02-15-2005 09:41 AM



Advertisments