in reply to word count
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(/ /) - 1);
and then you don't have to check for blank lines.$totalcount += split(' ');
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 |