Programming models and shaders II
This assignment was an introduction to TCL - Tool Command Language. Basically by a given text input the program should filter the words in the text according to some decision rule The decision rule for this project was the word to end in s and, if there are punctuation marks after s, they should be elliminated.
The text input is :
forms of things. From about the age of fifty I produced a number of
designs, yet of all I drew prior to the age of seventy there is truly
nothing of any great note. At the age of seventy-three I finally came to
understand somewhat the true nature of birds, animals, insects, fishes -
the vital nature of grasses and trees. Therefore, at eighty I shall
gradually have made progress, at ninety I shall have penetrated even
further the deeper meaning of things, at one hundred I shall have
become truly marvelous, and at one hundred and ten, each dot, each line
shall surely possess a life of its own. I only beg that gentlemen of
sufficiently long life take care to note the truth of my words.
My solution is:
set infile "H:/vsfx419/tcl/text.txt"
set hostDir [ file dirname $infile ]
set outfile "$hostDir /outtext.txt"
proc procedura1 { infile outfile } {
set out [ open $outfile w]
set in [open $infile r]
while { [eof $in ] != 1 } {
gets $in line
foreach item $line {
set laststring [ string length $item ]
set k [ string last "s" $item 10 ]
if { ( [ expr { 2 + $k }] >= $laststring )} {
if { $k > 0 } {
if { ( [ expr { 2 + $k }] == $laststring ) || ( $k > 0 ) } {
set ou [ string trim $item "." ]
set ou [ string trim $ou "," ]
puts $ou
puts $out $ou
}
}
}
}
}
close $in
close $out
}
procedura1 $infile $outfile
The return values are
forms
things
designs
is
birds
animals
insects
fishes
grasses
trees
progress
things
marvelous
possess
its
words