|
From: Andreas K. <and...@ac...> - 2009-10-06 18:35:41
|
George Petasis wrote:
> TIP #358: SUPPRESS EMPTY LIST ELEMENT GENERATION FROM THE SPLIT COMMAND
Possible solutions without having to add options to a builtin ...
proc split-without-empty-elements-1 {list} {
return [lsearch -all -inline -not [split $list] {}]
# Thanks to spjuth.
# This is 8.4+
}
# And for older Tcl's without the relevant lsearch options ...
proc split-without-empty-elements-3 {list} {
set res {}
foreach x [split $list] {
if {$x eq {}} continue
lappend res $x
}
return $res
}
proc split-without-empty-elements-2 {list} {
package require struct::list
return [struct::list filterfor x [split $list] {$x ne {}}]
}
--
Sincerely,
Andreas Kupries <an...@ac...>
Developer @ <http://www.activestate.com/>
|