#!/usr/bin/perl
while (<>) {
foreach (split) {
$total++;
next if /\W/;
$valid++;
$count{$_}++;
}
}
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