Sunday, 1 March 2009

Counting totalwords,validwords, each word count in a file?


while (<>) {

foreach (split) {
next if /\W/;



print "total words= $total, validwords = $valid \n";
foreach $word (sort keys %count) {

print "$word was seen $count{$word} times.\n";


Note : We can pass any number of files to this program, as $lt;> - the diamond operator takes all the command line arguments (file names) specified.

No comments:

Post a Comment

Tweets by @sriramperumalla