Data structures 嵌套字典中的值设置问题

Data structures 嵌套字典中的值设置问题,data-structures,dictionary,tcl,Data Structures,Dictionary,Tcl,我正在编写一个TCL脚本来解析Firebug评测控制台的HTML输出。首先,我只想在每个文件的基础上累积方法调用的数量。为此,我尝试使用嵌套字典。我似乎已经得到了第一个正确的级别(其中file是键,method是值),但没有得到第二个嵌套级别,method是值,count是键 我已经阅读了dictionary的更新命令,所以我愿意使用它进行重构。我的TCL使用又开又关,所以提前感谢您的帮助。下面是我的代码和一些示例输出 foreach row $table_rows { regexp {

我正在编写一个TCL脚本来解析Firebug评测控制台的HTML输出。首先,我只想在每个文件的基础上累积方法调用的数量。为此,我尝试使用嵌套字典。我似乎已经得到了第一个正确的级别(其中file是键,method是值),但没有得到第二个嵌套级别,method是值,count是键

我已经阅读了dictionary的更新命令,所以我愿意使用它进行重构。我的TCL使用又开又关,所以提前感谢您的帮助。下面是我的代码和一些示例输出

foreach row $table_rows {
    regexp {<a class="objectLink objectLink-profile a11yFocus ">(.+?)</a>.+?class=" ">(.+?)\(line\s(\d+)} $row -> js_method js_file file_line

    if {![dict exists $method_calls $js_file]} {
        dict set method_calls $js_file [dict create]
    }

    set file_method_calls [dict get $method_calls $js_file]

    if {![dict exists $file_method_calls $js_method]} {
        dict set file_method_calls $js_method 0
        dict set method_calls $js_file $file_method_calls
    }

    set file_method_call_counts [dict get $file_method_calls $js_method]
    dict set $file_method_calls $js_method [expr 1 + $file_method_call_counts]
    dict set method_calls $js_file $file_method_calls
}

dict for {js_file file_method_calls} $method_calls {
    puts "file: $js_file"
    dict for {method_name call_count} $file_method_calls {
        puts "$method_name: $call_count"
    }
    puts ""
}

dict set
命令与Tcl中的任何setter命令一样,将变量的名称作为其第一个参数。我敢打赌:

dict set $file_method_calls $js_method [expr 1 + $file_method_call_counts]
应该读到:

dict set file_method_calls $js_method [expr {1 + $file_method_call_counts}]

(同时,为了速度和安全,请用括号表示。)

$
或no
$
,问题是:)你
dict set file_method_calls $js_method [expr {1 + $file_method_call_counts}]