| |||||||||||
Passing array values as parameters Posted by neo (The Architect), 20 May 2005 How can I pass array values as parameters to a function.For e.g. I have an array IP address and depending on a command line arg (say a mean 10.10.10.10) I want to telnet to a certain host using expect. How do i do this? I tried passing the array val using $ARRAY($ARG) but this gives me an error saying Quote:
where var1 is the argument for $ARRAY($ARG) in the proc Posted by admin (Graham Ellis), 21 May 2005 Here's an example of passing an array member into a function.Code:
Which gives these results Code:
Can you supply me with a similar sample piece of code that shows the problem you're having ... I don't think its directly to do with passing from the array - it's some other problem perhaps. As a footnote - if you need to pass a complete array into a proc, you should call be name and use the upvar command. There are lots of examples of upvar - a feature that people always take a while to grasp - at http://www.wellho.net/resources/T207.html. Posted by neo (The Architect), 21 May 2005 Code:
Posted by neo (The Architect), 21 May 2005 Ok i think I got it the args should be passed in parentheses I had done this but I had separated them with commas and that did not work. Posted by admin (Graham Ellis), 21 May 2005 The proc command takes three parameters and yours has five. I suspect your code should readproc login2host {userName userPass prompt} { and not proc login2host userName userPass prompt { (note the extra curly braces that I've added) OK - we both posted at the same time. Glad it sorted anyway Posted by neo (The Architect), 21 May 2005 Yeah I changed that and it works fine now. I have another doubt though. I would like to execute a list of commands and receive expected responses. Among an array or a list which one would be better/easier? Posted by admin (Graham Ellis), 21 May 2005 In general "lists v arrays" ... you would choose a list if you want the elements to be in order (as a list is an ordered collection) and an array if you want to be able to select them quickly by key (as an array in Tcl is an unordered collection)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.
|
| ||||||||||
PH: 01144 1225 708225 • FAX: 01144 1225 793803 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho |