Reputation: 21
I want to write a TCL program for a given input string "Hello I Am Fine" , whose output must be: "Fine Am I Hello"
Also Want to know, how to find the last element within a list of elements?
Eg: [list 10 20 30 40 50 60 70 80 90 100]
-- So from this list i want to use the last element.
Thanks.
Upvotes: 1
Views: 786
Reputation: 15163
If you need the last element of a list, you can access it with
lindex $list end
If you want to know the index of the last element, use
expr {[llength $list] - 1}
If you want to reverse a list, use
set newList [lreverse $list]
Simple as that.
And for the the Input/Output thing, I suggest first split
it into a list, then reverse it, and join
the result again. I leave it to you as exercise.
Upvotes: 7