[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [MacPerl] Counting Words



At 0.34 -0400 1999.05.21, Michael D. Kirkpatrick wrote:
>I am trying to get a word count from a string.
>
>$a="This is some sample text."

If you know that your words are all space delimited:

   $w_cnt = $a =~ tr/ / /;
   $w_cnt++;

or, you could put in some pre-processing to make sure:

   $a =~ s/^\s+//;
   $a =~ s/\s+$//;
   $a =~ s/(\s)+/ /g;

------------
Paul Hackett
phackett@cstone.net



===== Want to unsubscribe from this list?
===== Send mail with body "unsubscribe" to macperl-request@macperl.org