diff options
author | dkf <donal.k.fellows@manchester.ac.uk> | 2003-07-15 22:07:36 (GMT) |
---|---|---|
committer | dkf <donal.k.fellows@manchester.ac.uk> | 2003-07-15 22:07:36 (GMT) |
commit | 4aa5d2c8459ece48ce92e83dedfd7a5c992aa7fa (patch) | |
tree | 8bd6f6ff52ac52e6539f49f1736d4f7639599666 /doc | |
parent | 15a36c2b44761be8ef9d533a938f41d2c7748ad5 (diff) | |
download | tcl-4aa5d2c8459ece48ce92e83dedfd7a5c992aa7fa.zip tcl-4aa5d2c8459ece48ce92e83dedfd7a5c992aa7fa.tar.gz tcl-4aa5d2c8459ece48ce92e83dedfd7a5c992aa7fa.tar.bz2 |
Added examples from David Welton [Patch 763312]
Diffstat (limited to 'doc')
-rw-r--r-- | doc/array.n | 55 |
1 files changed, 54 insertions, 1 deletions
diff --git a/doc/array.n b/doc/array.n index b04c89f..3839e77 100644 --- a/doc/array.n +++ b/doc/array.n @@ -5,7 +5,7 @@ '\" See the file "license.terms" for information on usage and redistribution '\" of this file, and for a DISCLAIMER OF ALL WARRANTIES. '\" -'\" RCS: @(#) $Id: array.n,v 1.8 2000/09/07 14:27:45 poenitz Exp $ +'\" RCS: @(#) $Id: array.n,v 1.8.18.1 2003/07/15 22:07:37 dkf Exp $ '\" .so man.macros .TH array n 8.3 Tcl "Tcl Built-In Commands" @@ -115,6 +115,10 @@ The return value is a search identifier that must be used in \fBarray nextelement\fR and \fBarray donesearch\fR commands; it allows multiple searches to be underway simultaneously for the same array. +It is currently more efficient and easier to use either the \fBarray +get\fR or \fBarray names\fR, together with \fBforeach\fR, to iterate +over all but very large arrays. See the examples below for how to do +this. .VS 8.4 .TP \fBarray statistics \fIarrayName\fR @@ -134,6 +138,55 @@ an array variable, then the command unsets the entire array. The command always returns an empty string. .VE 8.3 +.SH EXAMPLES +.CS +array set colorcount { + red 1 + green 5 + blue 4 + white 9 +} + +foreach {color count} [array get colorcount] { + puts "Color: $color Count: $count" +} + => Color: blue Count: 4 + Color: white Count: 9 + Color: green Count: 5 + Color: red Count: 1 + +foreach color [array names colorcount] { + puts "Color: $color Count: $colorcount($color)" +} + => Color: blue Count: 4 + Color: white Count: 9 + Color: green Count: 5 + Color: red Count: 1 + +foreach color [lsort [array names colorcount]] { + puts "Color: $color Count: $colorcount($color)" +} + => Color: blue Count: 4 + Color: green Count: 5 + Color: red Count: 1 + Color: white Count: 9 + +array statistics colorcount + => 4 entries in table, 4 buckets + number of buckets with 0 entries: 1 + number of buckets with 1 entries: 2 + number of buckets with 2 entries: 1 + number of buckets with 3 entries: 0 + number of buckets with 4 entries: 0 + number of buckets with 5 entries: 0 + number of buckets with 6 entries: 0 + number of buckets with 7 entries: 0 + number of buckets with 8 entries: 0 + number of buckets with 9 entries: 0 + number of buckets with 10 or more entries: 0 + average search distance for entry: 1.2 +.CE + .SH "SEE ALSO" list(n), string(n), variable(n), trace(n) |