Click to See Complete Forum and Search --> : Need a word counter
rugrat15834
06-04-2006, 05:44 PM
I'm putting a script together and need to be able to count the number of words going into a textarea in a form. Counting the number of characters is no problem with length($field) but I would just like to count the words. I have found javascripts with counters right beside the textarea box but want to count the words instead. Also, is there any way of limiting the amount of chars per word?. Any help would be much appreciated, Dave
Jeff Mott
06-05-2006, 01:19 PM
my $n = 0;
$n++ while $SomeString =~ m/[\w']+/g;
rugrat15834
06-07-2006, 01:07 AM
Thanx a million for the reply-just one question-does $n represent the field the words are being counted from? Dave
Jeff Mott
06-07-2006, 01:14 AM
No. Words are being counted from $SomeString. $n is the number of words.
JulianJ
06-09-2006, 01:37 AM
Here is another oldie:
my $wordCount = () = $textToTest =~ m/[\w']+/g;
Almost the same as above but without the loop and var init. Probably isn't much, if any, faster, however.
Julian
P.S. First post. :)