in reply to word count

Your word count should be 48 not 47. The problem is with this line:
$totalcount += (split(/ /) - 1);
If a line begins with whitespace, then subtracting one is correct, but otherwise it isn't. A better way to do this is:
$totalcount += split(' ');
and then you don't have to check for blank lines.

Another simple way to perform the count:

#!/usr/bin/perl -n while (m/\w+/g) { $count++ } END { print "count: $count\n" }

Replies are listed 'Best First'.
Re^2: word count
by graff (Chancellor) on Jun 04, 2008 at 01:00 UTC
    Fore! (I couldn't resist :)
    #!/usr/bin/perl -ln $t+=@a=/\w+/g;END{print$t}
    47 bytes, counting the shebang and two LFs; 26 bytes for the one-line script by itself. And it gives with the correct answer, too (48 "words" for the input text in question).