Home Accessibility Courses Twitter The Mouth Facebook Resources Site Map About Us Contact
For 2023 (and 2024 ...) - we are now fully retired from IT training.
We have made many, many friends over 25 years of teaching about Python, Tcl, Perl, PHP, Lua, Java, C and C++ - and MySQL, Linux and Solaris/SunOS too. Our training notes are now very much out of date, but due to upward compatability most of our examples remain operational and even relevant ad you are welcome to make us if them "as seen" and at your own risk.

Lisa and I (Graham) now live in what was our training centre in Melksham - happy to meet with former delegates here - but do check ahead before coming round. We are far from inactive - rather, enjoying the times that we are retired but still healthy enough in mind and body to be active!

I am also active in many other area and still look after a lot of web sites - you can find an index ((here))

Well House Consultants
You are on the site of Well House Consultants who provide Open Source Training Courses and business hotel accommodation. You are welcome to browse and use our resources subject to our copyright statement and to add in links from your pages to ours.
Other subject areas - resources
Java Resources
Well House Manor Resources
Perl Resources
Python Resources
PHP Resources
Object Orientation and General topics
MySQL Resources
Linux / LAMP / Tomcat Resources
Well House Consultants Resources
Extras Resources
C and C++ Resources
Ruby Resources
Tcl/Tk Resources
Web and Intranet Resources
Tcl/Tk module T206
Exercises, examples and other material relating to training module T206. This topic is presented on public courses Learning to program in Tcl, Tcl Programming, Tcl Programming

A variable might contain a series of words and, if it does, it can be treated in a special way, as a list through which your program can iterate. This module describes how such lists are handled, and goes on to cover list-related commands. Several sample programs show you how to make best use of lists.

Articles and tips on this subjectupdated
4455Working out distance between places, using OS grid references and a program in Tcl
In Great Britain, locations have Ordnance Survey grid reference positions which place them to within 100 metres. Our training centre / hotel is at ST907633 - that's   100 km square ST   90.7 km into that square from the west side   63.3 km into that squate from the south ...
4454Everything is a string - even a list
Almost all variables in Tcl are held as strings ... if you use integers and stirings in calculations such as expr and incr. the strings are converted back and forth intergally. Lists, too, are held as strings of characters in which chunks of string are counted / taken out as being elements in the list. ...
4209Lists in Tcl - fundamentals in a commented source code example
When I'm writing code demonstrations during class, they usually start off tidy and then get a bit scruffy as I add things in to answer delegate questions. For once last week, a Tcl list demonstration didn't get too untidy, so I give it you here with comments about what each few lines does.   # ...
3618lists and struct::list in Tcl - Introduction to struct::list and examples
In addition to the built in list commands, Tcl (since release 8.4) has been shipped with an additional struct::list package which includes additional procs (commands) you can use for manipulating lists. ::struct::list longestCommonSubsequence sequence1 sequence2 ?maxOccurs? ::struct::list longestCommonSubsequence2 ...
3582Tcl collections - lists, dicts and array
In Tcl, almost all variables are what is described as "pure" - which means that they hold data as strings of text which can be passed, substituted with a $ prefix, etc. Special interpretation on pure variables allows them to be treated as: • integers • floats • lists • dicts • ...
3583Expanding a list of parameters in Tcl - {*} and eval
In Tcl commands, parameters are separated by spaces, just like Tcl lists are. So it would sometimes be very useful to be able to write   set action {piemiddle apple}   set $action to take a list of parameters from a Tcl list - in this case setting the "piemiddle" variable to the ...
3415User defined sorting and other uses of callbacks in Tcl and Tk
When I output a table of results, I usually want it to be sorted in some way. In Tcl, I can use lsort to sort a list - there's an example of it running in a default way [here]. However, there's often a need to order records according to a non-default algorithm, and there are switches such as -integer ...
3394The difference between lists and strings - Tcl
There's not much difference between lists and strings in Tcl. In fact a list is just a string in a particular format, and if you split a string that contains just letters and spaces into a "list" you may not change anything AT ALL. Which means that if you make a coding error you may not spot it until ...
3285Extracting data from a string / line from file - Tcl
I never cease to be amazed at the number of different ways that data can be encoded into simple test lines ... and how the various languages that we teach can be used to manipulate / extract pertinent information. Today, on a Tcl Course, I was presented with data in this form:   T/N/R/Brother/Sister/Mum/Bob.txt/Esmerelda.txt/Sophie.txt The ...
1282Stringing together Tcl scripts
If you have a series of Tcl scripts that you want to run in a sequence, you can call all of them up in a master script using a series of source commands. This command switches input from the current script (sources) to the new source given as if the text of the sourced file was copied in to the original ...
463Splitting the difference
Perl's split function takes a string of text, and divides it up at a delimiter of your choice into a list of shorter strings ... it's one of the "power tool" functions of Perl and a vital part of the language. So how come that you can write a Tcl program and use its version of split - or omit the split ...
2468What are Tcl lists?
In Tcl, all variables (except 'arrays') are held as strings of text - and that includes lists. A list is a string which is treated as a collection of individual words, space separated, and you can then select individual words by their word number. And this means that if you have a simple, space separated ...
2472split and join in tcl and expect
Split and join in most languages convert strings of text into arrays / lists / collections of other sorts. But in Tcl, all variables are held as strings, so are split and join actually needed? If you're working with a collection of single words - no embedded spaces, no special characters, space delimited, ...
1601Replacing the last comma with an and
If I have a list, I'm likely to want to present it comma separated for the most part, but with the word "and" between the last two elements. "Cambridge, the M11, the M25, the M4, the A361 and Melksham" for example. Lists or arrays can be joined in almost any language with a function called join or ...
1405Sorting in Tcl - lists and arrays
Tcl's lsort command lets you sort a list - and that can be a list of the keys of an array. You can't sort the array, but once you have the list of keys you can sort that and use it to iterate through the array in any order that you like. As everything (except an array) is a string in Tcl, when you ...
1402Tcl - append v lappend v concat
Should you use append, lappend or even concat to add to variable in Tcl? append puts one string directly on the end of another, without adding any extra characters beyond those in the incoming variables. lappend treats the target string as a list, and will usually add an extra space on the end of it ...
1334Stable sorting - Tcl, Perl and others
Have you come across a STABLE sort? A Stable sort is one in which all the incoming elements which evaluate to an equal value when tested for sorting purposes remain in the same order in the output as they were in the input. Perhaps I had better give you an example. I have a log file and there's a ...
1283Generating traffic for network testing
"Why do you have a random number generator in a scientific language" ask some newcomers to the world of programming ... "shouldn't programming be an exact science?". Well yes, and no. It turns out that a random number generator is exceedingly useful in some instances. Here's a real, live example ...
781Tcl - lappend v concat
In Tcl, you can use the lappend command to add items on to a list, but it doesn't always do exactly what you wish it to. Let's say that I've got two lists - the first containing the early courses of a meal, and the second containing the latter courses. If I append the second list to the first, the ...
144Tcl sandwich - lists in Tcl
In Tcl, a list is simply a string that's held in the same format (i.e. with the same delimiters and protection) as a series of parameters to a Tcl command. The split command (which does a great deal in languages such as Perl and PHP) really does little more than change the delimiters if need be, and ...
Examples from our training material
acr2   Treating lines of data read from file as a list
arx   how an lsort callback works
days   A list of days
distance_between   Finding distances between places base on OS grid references
dt4u   extract field pairs from lines
expand   Handling a list of command parameters
fido   Open and read a file line by line
growth   station growth program
liimp   List basics in a nutshell
os_letters.txt   Easting and Northing additions for OS grid references
pk4.tcl   Generate a series packet sizes for network testing
slist   list manipulation with struct::list
stdlook   Look up Florida dialling codes
Background information
Some modules are available for download as a sample of our material or under an Open Training Notes License for free download from [here].
Topics covered in this module
How lists are handled in Tcl.
List-related commands.
Creating and modifying lists.
Extracting information from a list.
Manipulating lists to create other lists.
Sample programs using lists.
Reading an access log file.
Complete learning
If you are looking for a complete course and not just a information on a single subject, visit our Listing and schedule page.

Well House Consultants specialise in training courses in Tcl/Tk, Expect,Ruby, Lua, Python, Perl, PHP, and MySQL. We run Private Courses throughout the UK (and beyond for longer courses), and Public Courses at our training centre in Melksham, Wiltshire, England. It's surprisingly cost effective to come on our public courses - even if you live in a different country or continent to us.

We have a technical library of over 700 books on the subjects on which we teach. These books are available for reference at our training centre.

You can Add a comment or ranking to this page

© WELL HOUSE CONSULTANTS LTD., 2024: 48 Spa Road • Melksham, Wiltshire • United Kingdom • SN12 7NY
PH: 01144 1225 708225 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho

PAGE: http://www.wellho.net/resources/T206.html • PAGE BUILT: Sun Oct 11 14:50:09 2020 • BUILD SYSTEM: JelliaJamb