Saturday, 29 August 2015

Tool Command Language- Lecture 8 ( search list)

Use of lsearch , lindex and lsort 
a)- lsearch

syntax.
set list {{item1} [item2}...}
set variable [lsearch  $list  item]
it will return index of item. Remember it starts from 0.
Example:

set p {{java 1991} {c 1987} {python 2000} {tcl 2005}} 
set x [lsearch $p "python 2000"]

puts $x 

out put : 2
Note: if output is -1 then the searched value is not present in list.

b) - lindex

syntax.
set list {{item1} [item2}...}
puts [lindex  $list  index(number)]
it will return value at index in list .

Example:

set p {{java 1991} {c 1987} {python 2000} {tcl 2005}} 
puts  [lindex $p 3]
out put : tcl 2005

c)-lsort
syntax.
set list {{item1} [item2}...}
lsort $list
Example:

set p {{java 1991} {c 1987} {python 2000} {tcl 2005}} 
lsort  $p
out put : {c 1987} {java 1991} {python 2000} {tcl 2005}


No comments:

Post a Comment

Grammar Mistakes in Technical Paper Writing

Let me share some experience in this post with you. I'm currently in the second year of my Ph.D. program. We are in the middle of paper...