Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/image-processing/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Tcl 如何在数组中存储命令行参数_Tcl_Expect - Fatal编程技术网

Tcl 如何在数组中存储命令行参数

Tcl 如何在数组中存储命令行参数,tcl,expect,Tcl,Expect,如何在tcl中的数组中存储命令行参数 我正在尝试将命令行参数(argv)存储在数组中。argv不是数组吗?我尝试了以下代码,但对我无效 proc auto args { global argv set ifname [lindex $argv 0] puts "***********$ifname" puts "$argv(2)" for { set index 1} { $index < [array size argv ] } { incr in

如何在tcl中的数组中存储命令行参数

我正在尝试将命令行参数(argv)存储在数组中。argv不是数组吗?我尝试了以下代码,但对我无效

proc auto args {
    global argv
    set ifname [lindex $argv 0]
    puts "***********$ifname"
    puts "$argv(2)"
    for { set index 1} { $index < [array size argv ] } { incr index } {
       puts "argv($index) : $argv($index)"
    }
}
#Calling Script with arguments
auto {*}$argv
proc自动参数{
全局argv
设置ifname[lindex$argv 0]
放入“*********$ifname”
放入“$argv(2)”
对于{set index 1}{$index<[array size argv]}{incr index}{
放置“argv($index):$argv($index)”
}
}
#使用参数调用脚本
自动{*}$argv

Tcl的
argv
global是一个列表,而不是一个数组,因为顺序很重要,列表是执行参数的完全合理的方式。这就是为什么使用
lindex
(和其他列表操作)的原因。您可以转换为数组,但大多数代码最终会对此感到“惊讶”。因此,最好为其使用不同的数组名称(“
参数”
”):


Tcl的
argv
global是一个列表,而不是一个数组,因为顺序很重要,列表是执行参数的完全合理的方式。这就是为什么使用
lindex
(和其他列表操作)的原因。您可以转换为数组,但大多数代码最终会对此感到“惊讶”。因此,最好为其使用不同的数组名称(“
参数”
”):


在Tcl术语中,argv是一个列表而不是数组,因此您可以使用lindex访问其元素并使用llength查找其大小。请注意,在Tcl中,
array
一词在其他语言中并不表示数组。确实要数组而不是列表吗?即使你确定你想要一个键->值对数据结构,你确定你想要一个数组而不是一个dict吗?在Tcl术语中,argv是一个列表而不是数组,所以你可以使用lindex访问它的元素和llength来找到它的大小。请注意,在Tcl中,
array
这个词在其他语言中并不意味着数组。确实要数组而不是列表吗?即使您确定需要密钥->值对数据结构,您确定需要数组而不是dict吗?
proc argumentsToArray {} {
    global argv arguments
    set idx 0
    unset -nocomplain arguments; # Just in case there was a defined variable before
    array set arguments {};      # Just in case there are no arguments at all
    foreach arg $argv {
        set arguments($idx) $arg
        incr idx
    }
}

argumentsToArray
puts "First argument was $argument(0) and second was $argument(1)"