Advanced Search
Mail us
Home    Manuel    Links    Faq    Submit a tcl/tk Reference    Contact Us

    Some examples tcl/tk codes     Man of Bwidget     Man of blt     mkwidget screenshots     TkOgl     Video Demo real.

  pass an array into a proc?
 Use upvar rather than try to use global variables when possible.  If
the function is event driven, you are forced to use global variables.

# print elements of an array
proc show_array arrayName {
    upvar $arrayName myArray

    foreach element [array names myArray] {
       puts stdout "${arrayName}($element) =  $myArray($element)"

set arval(0) zero
set arval(1) one
show_array arval

To return an array from a procedures, just take the array name in as an
argument, as above.  Any changes you make in the array will be made in
the parent`s array as well.

Extended Tcl introduces a concept called keyed lists which are arrays
made out of lists of key-value pairs and can be passed by value to routines,
over networks, etc.