Forum Moderators: coopster & phranque

Message Too Old, No Replies

Getting rid of punctuation marks in perl

         

dreaming of nascar

6:32 pm on Apr 22, 2003 (gmt 0)

10+ Year Member



I have a script that breaks each word apart and then searches to find the word in the array. A problem that I am having is that if a word is at the end of a sentence, the two words do not match because of the punctuation mark. For example, if the word I am looking for is "computer" and that word does appear in the array, but it was at the end of a sentence it would look something like this: "computer." or "computer!". I was wondering if there was a command that I can use to search the current element in the array and delete a punctuation mark if necessary. I know of the chop() function, but do not know if that will work for this situation or not. Any advice would be appreciated. Thanks!

D O N

DrDoc

7:22 pm on Apr 22, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Well, you could also make the search match the punctuation mark...

Otherwise, do this to remove punctuations in a string:

$string =~ s/[?;:!,.'"]//g;