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 2023 (and 2024 ...) - we are now fully retired from IT training.
We have made many, many friends over 25 years of teaching about Python, Tcl, Perl, PHP, Lua, Java, C and C++ - and MySQL, Linux and Solaris/SunOS too. Our training notes are now very much out of date, but due to upward compatability most of our examples remain operational and even relevant ad you are welcome to make us if them "as seen" and at your own risk.

Lisa and I (Graham) now live in what was our training centre in Melksham - happy to meet with former delegates here - but do check ahead before coming round. We are far from inactive - rather, enjoying the times that we are retired but still healthy enough in mind and body to be active!

I am also active in many other area and still look after a lot of web sites - you can find an index ((here))
Extracting list args passed to a procedure

Posted by Nuts (Nuts), 9 October 2007
Hi,
     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  192.168.200.1
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 192.168.200.1 10001}

Inside connect procedure........

Value of cmdtype : TL1 192.168.200.1 10001
------------------------------------------------------------------------------------------

Kindly help me in this.

regards,
Neetesh




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:

Code:
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

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


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.

regards,
Nuts



This page is a thread posted to the opentalk forum at www.opentalk.org.uk 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., 2024: Well House Manor • 48 Spa Road • Melksham, Wiltshire • United Kingdom • SN12 7NY
PH: 01144 1225 708225 • FAX: 01144 1225 793803 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho