
Code: Select all
set lines [llength [split [read [set fp [open "FILE.NAME" w]]] "\n"]]
close $fp
Another way is to use OS utilities like "wc" (wordcount). A while loop with an increasing counter usually is not that efficient in terms of CPU usage although memory needs are low.caesar wrote:Well, not all the things are simple as they look like.. The usage of the 'foreach' thing is logical to be used. I don't have any ideea (at this moment) of another way to do the same thing. Combining mine and ppslim's reply you should solve this in a sec.. Heh..
wc --help wrote: Usage: wc [OPTION]... [FILE]...
Print line, word, and byte counts for each FILE, and a total line if
more than one FILE is specified. With no FILE, or when FILE is -,
read standard input.
Code: Select all
set file "FILE.NAME"
set lines [llength [split [read -nonewline [set fp [open $file r]]] "\n"]]
close $fp