Friday, April 3, 2009

Last Element in a Tcl List

Oh, thank you Tcl, for providing the special string end. That way I can get the last element in a list with:

[lindex $mylist end]

What a relief! I was about to type:

[lindex $mylist [expr {[llength $mylist] - 1}]]

And if I had had to type that, my head would have exploded. Fortunately, I got away with just a pulsing vein on my temple at the thought of a pseudo-keyword like end.

2 comments:

Anonymous said...

Thanks, that was useful to me, poor tcl beginner.

Anonymous said...

This is the best one line blog I have ever seen. Thanks for posting the tip.