Simple Array problem(unable to pass to a procedure)



Hi

I am a newbie to TCL/TK. I wrote a simple program to create a data
structure using arrays. The following is the code


-----------------------------------------------------------------------------------------------------------------------------------------------------------

#Following is the procedure which creates a data structure using
arrays for an argument list passed to it

proc create_data_table {arg_list} {

puts "Argument list passed to procedure : $arg_list"

foreach {key data} $arg_list {
set data_table($key) $data
puts "Key $key : Data $data_table($key)"
}
}


#Following is the data processing procedure which takes a data
structure as an argument

proc data_process {data_table_list} {
array set my_data_table_list $data_table_list
foreach {key} $my_data_table_list {
puts "Processing $key with Data $my_data_table_list($key)"
}
puts "End of dummy process\n"
}


#Following is the declaration of my data_structure as a global

global data_table
array set data_table {}


#Following is the simple loop to create a list from command line
arguments

set arglist {}

foreach argument $argv {
lappend arglist $argument
}

puts $arglist

# Create the data structure by calling the process "create data table"
create_data_table $arglist

# Call the data processing procedure by serializing the array through
the list using "array get" command
data_process [array get $data_table]

-----------------------------------------------------------------------------------------------------------------------------------------------------------

I save the file as arr_data_struct.tcl and in my cygwin terminal, I
run the following
%tclsh arr_data_struct.tcl data1 key1 data2 key2 data3 key3 data4 key4

The error that flags is as follows :-

can't read "map_table": variable is array
while executing "data_process [array get $data_table]"
(file "dummy_map_test.tcl" line 41)


Please help me in understanding the error and what s going wrong

Thank you

.



Relevant Pages

  • Re: Simple Array problem(unable to pass to a procedure)
    ... You have to address an array by reference and not by value. ... foreach $my_data_table_list { ... # Create the data structure by calling the process "create data table" ... # Call the data processing procedure by serializing the array through ...
    (comp.lang.tcl)
  • Re: Simple Array problem(unable to pass to a procedure)
    ... proc data_process { ... foreach $my_data_table_list { ... array set data_table ... # Call the data processing procedure by serializing the array through ...
    (comp.lang.tcl)
  • Re: [PHP] foreach() using current() strange beahvior
    ... that's expected as foreach moves the internal array pointer, ... When using the internal pointer just by calling current(so not moving ... Unless the array is referenced, foreach operates on a copy of the ...
    (php.general)
  • Re: a question about for and foreach
    ... foreach (@array) { ... why @array are changed after this foreach loop!!! ... The "foreach" loop iterates over a normal list value and sets the ... If any element of LIST is an lvalue, you can modify it by modifying ...
    (perl.beginners)
  • SUMMARY: Help! Self Induced 6540 Catastrophe
    ... firmware command for a StorageTek 6540 to revert a 'reset array' ... rather than manually recreating the LUNs. ... I've finally caught up after losing everything on this array. ...
    (SunManagers)