Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
And for some reason it counts a slightly different number of words! But not like one less or one more, it's not at all consistent!! WHY oh WHY will it not count the numbers of words correctly??? Can anyone help me? Am I doing something REALLY dumb?? Katy Mforeach $sentence(@sentences) { #print FILE "$sentence\n"; @words = split(/[^\w'a-zA-Z0-9_'-?]/,$sentence); $Counter =0; foreach $word(@words){ $Counter = $Counter+1; print ("$word\n"); } $sentence_count{($Counter)} = $sentence_count{($Counter)}+1; } while (($sentence_count,$word_count) = each(%sentence_count)) { print ("There are $word_count sentences of $sentence_count words\n +"); } <P>
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Sentence Measurer
by Beatnik (Parson) on Apr 11, 2001 at 22:17 UTC | |
|
Re: Sentence Measurer
by mirod (Canon) on Apr 11, 2001 at 22:18 UTC | |
|
Re: Sentence Measurer
by larsen (Parson) on Apr 11, 2001 at 23:02 UTC | |
|
Re: Sentence Measurer
by twerq (Deacon) on Apr 11, 2001 at 22:20 UTC | |
|
Re: Sentence Measurer
by suaveant (Parson) on Apr 11, 2001 at 22:14 UTC | |
|
Re: Sentence Measurer
by c-era (Curate) on Apr 11, 2001 at 22:15 UTC |