in reply to Counting the frequency of words in a string
I think the hardest part would be to define what makes "a word".
Given the definition was everything that doesn't match \W, this could do it:
my ( %wordcount, $relevancy ); for ( split /\W+/, $string ) # gets a list of all words { $wordcount{$_}++; } foreach my $word ( @list_of_words ) { $relevancy += $wordcount{$word}; }
I know there are smarter ways, for this can consume a lot of memory. Read on... =)
Cheers, Sören
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Counting the frequency of words in a string
by cez (Novice) on Dec 02, 2004 at 22:12 UTC | |
by cez (Novice) on Dec 02, 2004 at 22:19 UTC | |
by Eimi Metamorphoumai (Deacon) on Dec 02, 2004 at 22:26 UTC |