#!/usr/local/bin/perl

$wordcount = 0;
while ($line = <>) {
        # this isn't the best possible pattern to split with,
        # but it'll do until you've finished Day 7
        @words = split(/ /, $line);
        $wordcount += @words;
}
open (MESSAGE, "| mail dave") ||
        die ("Can't mail to userid dave.\n");
print MESSAGE ("Total number of words: $wordcount\n");
close (MESSAGE);
