home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.tcl
- Path: sparky!uunet!munnari.oz.au!metro!extro.ucc.su.OZ.AU!brucet
- From: brucet@extro.ucc.su.OZ.AU (Bruce Tulloch)
- Subject: How do I return an array as a list ?
- Message-ID: <brucet.726113122@extro.ucc.su.OZ.AU>
- Keywords: array list procedure
- Sender: news@ucc.su.OZ.AU
- Nntp-Posting-Host: extro.ucc.su.oz.au
- Organization: Sydney University Computing Service, Sydney, NSW, Australia
- Date: Mon, 4 Jan 1993 02:05:22 GMT
- Lines: 21
-
- Tcl Programmers,
-
- I'm new to tcl so maybe I've missed something, but is there an easier or
- more elegant way write a procedure which returns the contents of an array
- which exists in the context of the caller (or another explicit context)
- as a list of {index value} pairs than this ?
-
- 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
- }
-
- thank, bruce
- --
- bruce tulloch sydney australia - brucet@extro.ucc.su.oz.au
- ***complex problems have straight forward, easy to understand wrong answers***
-