DragnLord wrote:nml375 wrote:Splitting a second time?
I think you are abit confused 'bout splitting...
Split converts a string to a list, $t is a string since it originates from the binding. Hence it should (must) be splitted prior being used with any commands expecting a list as a parameter. Using your code with a "reason" such as "evil user typing {" would illustrate how your script was broken, and how split is necessary.
A bad habit, in my opinion, is not bothering to keep track whether the content of a variable is a string or a list (always considder user input to be a string, never a list).
you seem a bit confused about how lrange works
[lrange $x 0 end] may be used to force x to have list (as opposed to string) representation - this enhances performance in some situations.
NAME
lrange - Return one or more adjacent elements from a list
SYNOPSIS
lrange list first last
DESCRIPTION
List must be a valid Tcl list. This command will return a new list consisting of elements first through last, inclusive. First or last may be end (or any abbreviation of it) to refer to the last element of the list. If first is less than zero, it is treated as if it were zero. If last is greater than or equal to the number of elements in the list, then it is treated as if it were end. If first is greater than last then an empty string is returned. Note: ``lrange list first first'' does not always produce the same result as ``lindex list first'' (although it often does for simple fields that aren't enclosed in braces); it does, however, produce exactly the same results as ``list [lindex list first]''
just so we are clear here, both lrange and lindex work with lists, and want to have lists given to them, hence they begin with l.
Now, the difference between a string and a list is what is at issue here more than the commands. Because sure, anyone can use list commands on strings and string commands on lists. The problem is this isn't natural to do, so unexpected problems always arise, and must be compensated for.
Keep in mind, lists use curly bracing to denote list elements and fields. Strings do not. So any time you mistakenly give a list command a string with any curly braces in it, expect dilemma. Instead use [split $string] (this will protect the curly braces within the string from being interpreted as list elements or fields).
Instead of being arrogant and refusing to see that while your way is faster (not needing to split, indeed you save clock cycles). You need to see that it introduces more work later, extraneous filters and work arounds...