home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.tcl
- Path: sparky!uunet!psinntp!sugar!karl
- From: karl@NeoSoft.com (Karl Lehenbauer)
- Subject: Re: How do I return an array as a list ?
- Organization: NeoSoft Communications Services -- (713) 684-5900
- Date: Mon, 4 Jan 1993 05:48:14 GMT
- Message-ID: <C0BEsF.1K2@NeoSoft.com>
- Keywords: array list procedure
- References: <brucet.726113122@extro.ucc.su.OZ.AU>
- Lines: 29
-
- In article <brucet.726113122@extro.ucc.su.OZ.AU> brucet@extro.ucc.su.OZ.AU (Bruce Tulloch) writes:
- >proc arrayToList {array {context 1}} {
- > set names [uplevel $context array names $array]
- > if {![llength $names]} {return}
- > foreach name $names {
- > set item [echo $name [uplevel $context echo $[uplevel $context echo $array]($name)]]
- > lappend contents $item
- > }
- > return $contents
- >}
-
- Sure, use upvar. The proc below shows how:
-
- proc arrayToList {arrayName} {
- upvar $arrayName myArray
-
- set result ""
- foreach name [array names myArray] {
- lappend result "$name $myArray($name)"
- }
- return $result
- }
-
- Note that with upvar this sort of thing isn't so necessary, anyway, because
- you can use upvar to pass the names of arrays to procs, where the proc
- links into the actual array with upvar.
- --
- -- Email info@NeoSoft.com for info on getting interactive Internet access.
- "In a minute, I'll burp up your droid."
-