For Programmers: Free Programming Magazines  


Home > Archive > PERL Beginners > May 2006 > Count Punctuation Chars









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Count Punctuation Chars
lucas

2006-05-22, 7:41 pm

Hi,

I am trying to count the number of times a punctuation character occurs in a text file (I am trying to find out the number of commas, full stops and open and closed brackets and hyphens there are).

I have tried:

$count = $string =~ tr/[,]//;
print "number of commas: $count\n";

For each punctuation char but it doesn't seem to work for the hyphen char and only seems to count 1 occurrence.

How can I achieve this? I'm lost

Thanks
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com