Tcl : Working with array

Lets start with running tcl script below to try out some array command :

set ar(1) one
set ar(2) two
set ar(3) three

puts array_size:[array size ar]
puts array_get:[array get ar]
puts array_names:[array names ar]

foreach {key} [array names ar] {set x $ar($key); puts $x}

On example above we use 3 array subcommand :

  1. array size : return size of an array.
  2. array get : return list containing all key and value of an array.
  3. array names : return list containing all key of an array.

Result from running the script using tclsh is :

Bye !

Leave a Reply

Your email address will not be published. Required fields are marked *