Reputation: 13
I am reading some values from a file and reading them as data(signal1),data(signal2)
in one proc - read()
.
From this proc I am calling another proc usage_12(data(signal1))
and want to send data(signal1)
as argument and use in usage_12(args)
proc read() {args} {
#import data from a file and store {signal1 signal2} data
usage_12 $data(signal1)
}
proc usage_12 {args} {
foreach trq $args {
#iterate for all values
}
}
want to iterate in usage_12
for all values in data(signal1)
data(signal1) example contents:
1 2 3 4 5 6
Upvotes: 1
Views: 3397
Reputation: 95
you can use array get arrayname
and array set arrayname
for this purpose. It is done in following steps.
array get arrayname
array set arrayname $list
And then you will be able to use copy of array in the proc.proc print_array {key_vals} {
array set data $key_vals
foreach key [array names data] {
puts $data($key)
}
}
array set data [list 0 sdf 1 sddsf 2 dssd]
print_array [array get data]
Note: If you want to use same array ie not copy of array, you can use upvar.
Upvotes: 0
Reputation: 71538
args
is a special variable name for proc
s, you either need to change it, or indicate that you want to iterate on the elements of the first argument only:
proc usage_12 {data} {
foreach trq $data {
puts $trq ;# Just printing the value
#iterate for all values
}
}
Or
proc usage_12 {args} {
foreach trq [lindex $args 0] {
puts $trq ;# Just printing the value
#iterate for all values
}
}
Both of the above will print 1 through 6 on their own line.
Upvotes: 2