summaryrefslogtreecommitdiffstats
path: root/tests/langbench/wc.pl
blob: 085390865320d3521502af07daf0e81efba66a68 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
sub wordsplit
{
	chomp($_[0]);
	@list = ();
	$word = "";
	foreach $c (split(//, $_[0])) {
		if ($c =~ /\s/o) {
			push(@list, $word) if $word ne "";
			$word = "";
		} else {
			$word .= $c;
		}
	}
	push(@list, $word) if $word ne "";
	return @list;
}

$n = 0;
while (<>) {
	@words = &wordsplit($_);
	$n += $#words + 1;
}
printf "%d\n", $n;