Reputation: 43
$myList holds the contents of an array via array get.
lappend myList array get myArray * * *
puts "$myList"
{636174,736f756e64,30 6d656f77 666f78,736f756e64,30 796969
646f67,736f756e64,30 776f6f66 666f78,736f756e64,31 796970
646f67,736f756e64,31 6261726b 646f67,736f756e64,32 77756666}
My end result I am looking for is to gather all entries that are not connected by commas.
6d656f77 796969 776f6f66 646f67 6261726b 77756666
If I am to manually hardcode the values using lmap this outputs correctly.
% puts [lmap x {636174,736f756e64,30 6d656f77 666f78,736f756e64,30 796969 646f67,736f756e64,30 776f6f66 666f78,736f756e64,31 796970 646f67,736f756e64,31 6261726b 646f67,736f756e64,32 77756666} {if {[string first , $x] != -1} continue {set x}}]
6d656f77 796969 776f6f66 796970 6261726b 77756666
If I use the variable $myList this outputs null.
puts [lmap x $myList {if {[string first , $x] != -1} continue {set x}}]
The same happens with lsearch returning null too.
[lsearch -all -inline -not $myList *,*]
What am I doing wrong?
Upvotes: 0
Views: 526
Reputation: 71548
It looks like you are not lappend
ing properly and instead lappend
ing a whole list, into another.
array set myArray {
636174,736f756e64,30 6d656f77 666f78,736f756e64,30 796969
646f67,736f756e64,30 776f6f66 666f78,736f756e64,31 796970
646f67,736f756e64,31 6261726b 646f67,736f756e64,32 77756666
}
lappend myList [array get myArray]
Here, $myList
contains only one element, which itself then contains the different values. You should expand the list returned by array get
:
lappend myList {*}[array get myArray]
That said, to me it looks like all the keys in the array contain commas, and you need the values, so in this case, you might as well skip the lappend
:
set myList [lmap {key val} [array get myArray] {set val}]
# 776f6f66 796969 6d656f77 6261726b 796970 77756666
Upvotes: 2