#!/usr/local/bin/perl #MB Nov 2012 #script to check experiment stimuli #counts the number of lines in a file #counts number of words in a file and averages across lines #count the number of characters in a file and averages across words #BUT how do I count the number of words ON EACH LINE? while (<>) { chop; foreach $w (split) { $words++; $char = $char + length($w); #cumulative characters for all words } #$wordline = length($_); # this gives the character count per line instead of the word count; } #print "\n$. the sentence [$_] has $words words"; # this prints the sentence(good!) but counts the cumulative number of words for all sentences until that point instead of that sentence only print "\n$words words in this file\n"; $avwds = $words/$.; #average words per line $avch = $char/$words; #average characters per word print "there are $char characters in total"; print "\nthere are $. lines with an average of $avwds words per line"; print "\nthere are $words words with an average of $avch characters per word";