in reply to Sentence Measurer
You can simplify your code quite a bit:
#!/bin/perl -w use strict; my %sentence_count; foreach my $sentence(<DATA>) { $sentence=~ s/^\W+//; # remove leading non-words my $counter = split(/\W+/,$sentence); # split on non-words sequenc +e (\W+) # in scalar context split wi +ll return # the number of elements in +the generated list, # no need to count them ($co +unt= @word in your # example would work too) $sentence_count{($counter)}++; } while ( my($sentence_count,$word_count) = each(%sentence_count)) { print ("There are $word_count sentences of $sentence_count +words\n"); } __DATA__ one one two, two two. two two, two. three three three three three three three three three. three three, three
|
|---|