Re: Tcl faster than Perl/Python...but only with tricks...



Hello

Slightly off-topic. If you like that Python "trick" then you'd love
tcllib's fileutil::foreachLine. If you don't have tcllib then copy and
paste this to your file:

Thanks. I know Tcllib of course, but I did not use it, because it makes
things much more comfortable but much slower also. foreachLine is nice, but
when using Tcllib anyway, I would use fileutil::grep, which is also much
faster than foreachLine.

Nevertheless, your hint gave me the idea to try this one:
---
proc grep_for {} {
for {set f [open bigfile r]} {[gets $f line] >= 0} {} {
if {[string match -nocase "*destroy*" $line]} {
puts $line
}
}
}
---

Performance is nearly the same as the [while] version (while: 0.692s, for:
0.680s), but a little bit shorter.

Regards
Stephan

.