diff options
author | dkf <donal.k.fellows@manchester.ac.uk> | 2009-01-07 13:50:03 (GMT) |
---|---|---|
committer | dkf <donal.k.fellows@manchester.ac.uk> | 2009-01-07 13:50:03 (GMT) |
commit | e241610f648c4f00d9f6b5bff043a865ba8f0054 (patch) | |
tree | e8b7c8b063df8872c9deb7c0b8d279f4a07a3719 /doc/dict.n | |
parent | 71959308ac3589a49cde993adf47ef762cf8d8b9 (diff) | |
download | tcl-e241610f648c4f00d9f6b5bff043a865ba8f0054.zip tcl-e241610f648c4f00d9f6b5bff043a865ba8f0054.tar.gz tcl-e241610f648c4f00d9f6b5bff043a865ba8f0054.tar.bz2 |
Added more examples. [Tk Bug 2491235]
Diffstat (limited to 'doc/dict.n')
-rw-r--r-- | doc/dict.n | 28 |
1 files changed, 27 insertions, 1 deletions
@@ -4,7 +4,7 @@ '\" See the file "license.terms" for information on usage and redistribution '\" of this file, and for a DISCLAIMER OF ALL WARRANTIES. '\" -'\" RCS: @(#) $Id: dict.n,v 1.20 2008/12/10 11:15:05 dkf Exp $ +'\" RCS: @(#) $Id: dict.n,v 1.21 2009/01/07 13:50:03 dkf Exp $ '\" .so man.macros .TH dict n 8.5 Tcl "Tcl Built-In Commands" @@ -256,6 +256,32 @@ and are equivalent dictionaries (with different string representations). .SH EXAMPLES .PP +Basic dictionary usage: +.PP +.CS +# Make a dictionary to map extensions to descriptions +set filetypes [\fBdict create\fR .txt "Text File" .tcl "Tcl File"] + +# Add/update the dictionary +\fBdict set\fR filetypes .tcl "Tcl Script" +\fBdict set\fR filetypes .tm "Tcl Module" +\fBdict set\fR filetypes .gif "GIF Image" +\fBdict set\fR filetypes .png "PNG Image" + +# Simple read from the dictionary +set ext ".tcl" +set desc [\fBdict get\fR $filetypes $ext] +puts "$ext is for a $desc" + +# Somewhat more complex, with existence test +foreach filename [glob *] { + set ext [file extension $filename] + if {[\fBdict exists\fR $filetypes $ext]} { + puts "$filename is a [\fBdict get\fR $filetypes $ext]" + } +} +.CE +.PP Constructing and using nested dictionaries: .PP .CS |