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
Python, Lua and Tcl - public course schedule [here]
Private courses on your site - see [here]
Please ask about maintenance training for Perl, PHP, Java, C, C++, Ruby, MySQL and Linux / Tomcat systems

Phone System reconfiguration 11.1.2018 to 26.1.2018 - we are on email but incoming landline not available. Temp number 0797 4 925928
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., 2018: Well House Manor • 48 Spa Road • Melksham, Wiltshire • United Kingdom • SN12 7NY
PH: 01144 1225 708225 • FAX: 01144 1225 793803 • EMAIL: • WEB: • SKYPE: wellho