Training, Open Source computer languages
PerlPHPPythonMySQLApache / TomcatTclRubyJavaC and C++LinuxCSS 
Search for:
Home Accessibility Courses Diary The Mouth Forum Resources Site Map About Us Contact
For 2021 - online Python 3 training - see ((here)).

Our plans were to retire in summer 2020 and see the world, but Coronavirus has lead us into a lot of lockdown programming in Python 3 and PHP 7.
We can now offer tailored online training - small groups, real tutors - works really well for groups of 4 to 14 delegates. Anywhere in the world; course language English.

Please ask about private 'maintenance' training for Python 2, Tcl, Perl, PHP, Lua, etc.
Extracting list args passed to a procedure

Posted by Nuts (Nuts), 9 October 2007
     I am passing a list (containing strings) to  procedure. Now, if i try
to read the individual elements of the '"args" argument in the procedure I couldn't get the individual value of the strings passed.

## File1 :  test.tcl
## To connect to the NE
set cmdtype TL1
set ipaddr
set portaddr 10001
set params [list $cmdtype $ipaddr $portaddr ]
connect $params

## File2 : connect.tcl
proc connect {args} {

  if {[llength $args] < 1} {
       error "not enough args"

  puts "Value of args : $args\n"

  set cmdtype [lindex $args 0]
  set ipaddr [lindex $args 1]
  set portaddr [lindex $args 2]

   puts "Value of cmdtype : $cmdtype"

if {$cmdtype == "TL1"} {
       puts "Connecting TL1 interface..."

### Output ###
[neetesh@neetesh-OME expect_sample]$ ./test.tcl
Value of args : {TL1 10001}

Inside connect procedure........

Value of cmdtype : TL1 10001

Kindly help me in this.


Posted by admin (Graham Ellis), 9 October 2007
You're only passing a single list across, so there's only one thing in that list in the proc.   You need to look at the list within the list.   Here's an example of what I mean:

proc connect {args} {
       foreach thing $args {
               puts $thing
               foreach within $thing {
                       puts $within

set params [list tomato apple banana]
connect $params

And that runs as follows

earth-wind-and-fire:~/oct07 grahamellis$ tclsh ttc
tomato apple banana

For future note, if you can trim down you questions to fewer lines, it would be a huge help.  Thanks!

Posted by Nuts (Nuts), 10 October 2007
Thanks Graham !! It worked for me.


This page is a thread posted to the opentalk forum at and archived here for reference. To jump to the archive index please follow this link.

You can Add a comment or ranking to this page

© WELL HOUSE CONSULTANTS LTD., 2022: Well House Manor • 48 Spa Road • Melksham, Wiltshire • United Kingdom • SN12 7NY
PH: 01144 1225 708225 • FAX: 01144 1225 793803 • EMAIL: • WEB: • SKYPE: wellho