blob: 5dc17aa5beadbba246d55f65e0cc7eb3585925bd (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
proc wordsplit {str} {
set list {}
set word {}
foreach char [split $str {}] {
if {[string is space $char]} {
if {[string length $word] > 0} {
lappend list $word
}
set word {}
} else {
append word $char
}
}
if {[string length $word] > 0} {
lappend list $word
}
return $list
}
proc doit {file} {
set f [open $file r]
fconfigure $f -translation binary
set buf ""
set n 0
while {[gets $f buf] >= 0} {
set words [wordsplit $buf]
incr n [llength $words]
}
close $f
return $n
}
set total 0
foreach file $argv {
incr total [doit $file]
}
puts $total
|