proc tokenize {str {split " "}} {
set i -1
foreach v [split $str $split] {
uplevel 1 [list set [incr i] $v]
}
incr i
}
usage: tokenize $yourString ","
returns: the number of variables created (the first one is "0")
this seems realy complicated just to split a ',' is it faster ? does uplevel export it outside the proc ? or something cause unless its doing that i must be missing something cause the tokenize is local..
sorr just curious can't get a grip on uplevel just yet i know it is something like eval but .. thats it
Also string map can do the job for you, in only line. Regsub is also an alternative, but string map is faster.
Replace the comma's by an empty space. Now you have created a list with elements. Then foreach element in the list make a variable. Use a counter for the variable's name and the value will be the element.
·awyeah·
==================================
Facebook: jawad@idsia.ch (Jay Dee) PS: Guys, I don't accept script helps or requests personally anymore.
==================================
Ofloo wrote:this seems realy complicated just to split a ',' is it faster ? does uplevel export it outside the proc ? or something cause unless its doing that i must be missing something cause the tokenize is local..
It does what he requested. (creates the variable(s) in the scope the proc is invoked from)
awyeah wrote:Replace the comma's by an empty space. Now you have created a list with elements.
Wrong. You also need to escape alot of special characters. 'split' exists for a reason.