简体   繁体   中英

variable substitution in for each loop- tcl tk programming

I am trying to find out number of elements failed and the results are to be printed in a .csv file. this is my code,

set n_min_len 10
set n_max_len 50
set n_angle 60
foreach check {"min length" "max length" "angle"} \
        fail {$n_min_len $n_max_len $n_angle} {
   puts $file [format %30s%10s "$check...." "$fail"]
   }

I get output as min length....$n_min_len max length....$n_max_len and so on. Instead I wanted output as min length....10 max length....50

can someone help me, how to get this.

thank you!!

The problem is with this part:

{$n_min_len $n_max_len $n_angle}

The braces block any substitution. Instead you should write

"$n_min_len $n_max_len $n_angle"

or

[list $n_min_len $n_max_len $n_angle]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM