![]() |
Available news archives:
comp.lang.tcl
-
comp.lang.python
-
comp.security.firewalls
-
sci.crypt -
comp.lang.php -
comp.lang.javascript
|
|
comp.lang.tcl archiveRe: How to dynamically pass operators to if?
From: Donald Arseneau <asnd@triumf.ca>
Date: Thu Mar 09 2006 - 03:04:36 CET
Andrew Falanga <not_real@hp.com> writes:
> I have a situation where I'm trying to pass the comparison operator
> if { $val1 $oper $val2 } {
This used to work, long ago, but the round of expansion done by
if "$val1 $oper $val2" {
which might be just what you want, if this is not a performance
However, the performance optimization in expr is significant, and
if "\$val1 $oper \$val2" {
but you will do much better by testing within the expression syntax
if { $oper == ">" ? $val1 > $val2 : $val1 < $val2 } {
(But better to use a boolean flag rather than a string).
(wishing) 4 % time {expr "$val1 $oper $val2" } 10000
-- Donald Arseneau asnd@triumf.caReceived on Sun Apr 30 02:28:06 2006 |