I want to pass array and return array from a procedure, the following is the sample code i tried. But getting some errors..
set a(0) "11"
set a(1) "10"
set a(2) "20"
set a(3) "30"
set a(4) "40"
proc deleten somet {
upvar $somet myarr
for { set i 1} { $i < [array size myarr]} { incr i} {
set arr($i) $myarr($i)
}
return arr
}
array set some[array get [deleten a]]
parray some
when i run this code i get the following error wrong # args: should be "array set arrayName list". I'm pretty sure that i dont want to use list, how can i set the array returned from the proc to another array???
The step you were missing is that you return [array get arr]
rather than just arr
.
The following snippet works here
set a(0) "11"
set a(1) "10"
set a(2) "20"
set a(3) "30"
set a(4) "40"
proc deleten somet {
upvar $somet myarr
for { set i 1} { $i < [array size myarr]} { incr i} {
set arr($i) $myarr($i)
}
return [array get arr]
}
array set some [deleten a]
parray some
See How to pass arrays for further information.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With