Tcl 获取错误,因为没有这样的变量

Tcl 获取错误,因为没有这样的变量,tcl,Tcl,我想缩进一个文件的所有代码,其中所有行都从最左边开始。所以我写了代码 set fp [open without_spaces.tcl] set new_file [open final.tcl w+] set start 0 while {[gets $fp line] >= 0} { puts $line if {[regexp {\{$} $line]} { puts $new_file $nline incr $start

我想缩进一个文件的所有代码,其中所有行都从最左边开始。所以我写了代码

set fp [open without_spaces.tcl]
set new_file [open final.tcl w+]
set start 0
while {[gets $fp line] >= 0} {
    puts $line
    if {[regexp {\{$} $line]} {
        puts $new_file $nline
        incr $start
        #Now start brace is here, lets find closing brace
        continue
    } elseif {[regexp {\}$} $line]} {
        puts $new_file $nline
        incr $start -1
        continue
    }
    if {$start > 0} {
        puts $new_file "\t\t\t\t" $nline
    }
    if {[regexp {^\#} $line]} {}
        continue
    }
close $fp
close $new_file
但是这给了我错误无法读取“nline”:没有这样的变量,删除nline会给我一个空的输出文件。 请帮帮我


我知道这是一个愚蠢的问题。[仍然是一个NOOB]

制作
$nline
$line


这将在
final.tcl
上生成输出。我已经测试过了。

变量
nline
定义在哪里?您应该对变量执行增量操作,而不是对值执行增量操作。我仍然无法缩进代码,而不是
incr$start
,而是
incr start
将其更改为incr start,并将$nline更改为$line。final.tcl与不带_spaces.tcl的完全相同。现在该怎么办@迪内希