Search This Blog

Wednesday, September 13, 2023

Lists in TCL scripting

 LISTS keywords and It's Usage 

lindex

lindex is a keyword and it will print the index value of the list.
Example:
   set  NameList  "Naresh Prashanth Sanjeev Manoj  Rajendhar"
   puts [lindex $NameList 0] ; #it will print the 0th index of NameList i,e Naresh
   puts [lindex $NameList 1] 
   puts [lindex $NameList 2] 
         
Explanation:

List index will start from "0" 
Naresh    -----> index 0
Prashanth  ---> index 1
Sanjeev     ---> index 2
Manoj      ----> index 3
Rajendhar ---> index 4

*****************************************************************************

llength

llength is a keyword -it will give you the size of the list.

Example:           
  set  NameList  "Naresh Prashanth  Sanjeev Manoj Rajendhar"
  puts [lindex   $NameList 0] 
  puts [llength  $NameList ] ; #it will print 5 because 5 Names are there in the NameList  

****************************************************************************

lsort

lsort is a keyword -it will sort the list means ascending/Descending order of the List      

Example1:
 set  NumList  "0  9 8 1 3 4"
 puts [lsort $NumList  -ascending ] ; # it will print from small to big
 puts [lsort $NumList  -descending ] ; # it will print from big to small 

 Explanation 1:
 In this example I am taking numerical values     
 Ascending values --> small to big like 0 1 3 4 8 9
 Descending values --> big to small like 9 8 4 3 1 0

Example2:         
 set flist  "Banana Anar Avagado Watermelon Grapes Mango "
 puts [lsort $flist] ; # it will print in alphabetical order

*************************************************************************

lsearch

lsearch is a keyword to search for the element if it is matches it will return 0 otherwise it will return -1 

Example:
    set str "Nag Raju Chandu Mahi"
    lsearch $str Nag

************************************************************************


No comments:

Post a Comment

What is the sanity checks you have done for STA?

 Sanity checks for STA: Linking Checks: We need to check., is there any missing modules or missing pins in a library. this is done by link c...