user wrote:I think checking $arg as the first thing inside the proc would make the most sense. Then you would avoid all that work for nothing. No need to split an empty string just to find out it's empty
The best way to check if a variable is empty (imo) is
That's nice and all... but as in this case, we are interested in checking for TWO (2) arguments within arg... thus, if only one is set instead of two, your check would give it a pass, when it should have failed...
For this situation caesars (+users fix) would be the best answer:
Sir_Fz wrote:so if {[llength [split $arg]] == 2} { ... } will check if the second word is empty then it will do whatever.... ?
Not quite...
It will check if the length of the list is 2, implying that there are (no more than, and no less than) two non-empty elements within the [split $arg] list.
yes but i guess the reason would be more than one element
so the user would be [lindex [split $arg] 0] and the reason would be [lrange [split $arg] 1 end] so the llength wouldn't do it in this case ?
Sir_Fz wrote:yes but i guess the reason would be more than one element
so the user would be [lindex [split $arg] 0] and the reason would be [lrange [split $arg] 1 end] so the llength wouldn't do it in this case ?
To be honest, I wasn't really paying attention to the application, just the premise...
But yes, llength will still apply... just needs to be modded slightly...
It dosen't matter what arguments you use in order to function propertly. The [lindex [split $arg] 0] and the [lrange [split $arg] 1 end] are correct. Also, it can be equal or bigger than 2 or just equal or smaller or whatever you want, it will still work.
Once the game is over, the king and the pawn go back in the same box.
Actually, upon furthur inspection of this case, with the given data,
the llength [split $arg]] == 2 is the correct assertion, and I will explain why...
lol, yes you're right.. the mistake of skipping the ":" is very common
also if you see in the first code given "reason is set to [lindex $arg 1]" so its only 1 word too