Code: Select all
proc lremove { list element } {
# uplevel????
for {set i 0} {$i < [llength $list]} {incr i} {
if {[string match $element [lindex $list $i]]} { lreplace $list $i $i }
}
}
Code: Select all
array unset yourarray $element
And don't forget that the part you called 'element' is actually a PATTERN (glob), so to unset single elements, using the good old 'unset' would probably make your life alot easier.caesar wrote:something like this should do it..Don't forget to call globaly the array via an global yourarray and no need of $ in front of yourarray like $yourarray..Code: Select all
array unset yourarray $element
Code: Select all
proc lremove { list element } {
set temp ""
for {set i 0} {$i < [llength $list]} {incr i} {
if {![string match $element [lindex $list $i]]} { lappend temp [lindex $list $i] }
}
return "$temp"
}
Code: Select all
proc lremove { array_element list_element } {
global $array_element
for {set i 0} {$i < [llength $array_element]} {incr i} {
if {![string match $list_element [lindex $array_element $i]]} { lreplace $array_element $i $i }
}
}
Using array unset to unset single array elements does not work without escaping some chars in the pattern first. (you could argue it works most of the time, but that's not good enough)caesar wrote:he said and I quote "I just want to unset an element and not the whole array... " so.. that should do what he asked..
You seem to be a bit confused about arrays/listscerberus_gr wrote:lremove <array_element>(proc 1) or <listname> (proc 2) element (glob style)
Code: Select all
# usage: lremove <list> <glob pattern matched against element names>
# returns: the new list
proc lremove {list mask} {
set i 0
foreach elem $list {
if {[string match $mask $elem]} {set list [lreplace $list $i $i]} {incr i}
}
set list
}
# usage: array_unset <array name> <glob pattern matched against element names>
# returns: nothing
proc array_unset {array mask} {
upvar 1 $array arr
foreach elem [array names arr $mask] {unset arr($elem)}
}