| |||||||||||
| |||||||||||
Tcl 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 add protective \ { and } characters - again only if need be.
Here's an example where we're splitting and manipulating the contents of a sandwich. tcl>set sarnie "cheese, marmite, onion, pickle" tcl>set d4 [split $sarnie ,] tcl>set d4 cheese { marmite} { onion} { pickle} At this point, the braces have been added to protect the space character which is part of the individual ingredient tcl>foreach ingrid $d4 { =>puts [string trim $ingrid] =>} cheese marmite onion pickle I used string trim to remove the space before printing each element out Let's rejoin the ingredients into a string using the word "and" as the glue tcl>set d5 [join $d4 " and "] tcl>set d5 cheese and marmite and onion and pickle or as an alternative, print it out sorted into the order of ingedients with my favourite first ;-) tcl>lsort $d4 { marmite} { onion} { pickle} cheese tcl> (written 2004-12-08 01:50:44) Associated topics are indexed under T206 - Tcl/Tk - Lists
Some other Articles
Programming in isolationRecent technical articles example of Tcl namespaces and packages a comment on comments Tcl sandwich - lists in Tcl Network Camera Colour for access Too technical? Comparison Chart for Perl programmers - list functions Just provide a room and the students 1637 posts, page by page
Link to page ... 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33 at 50 posts per pageThis is a page archived from The Horse's Mouth at http://www.wellho.net/horse/ - the diary and writings of Graham Ellis. Every attempt was made to provide current information at the time the page was written, but things do move forward in our business - new software releases, price changes, new techniques. Please check back via our main site for current courses, prices, versions, etc - any mention of a price in "The Horse's Mouth" cannot be taken as an offer to supply at that price. Link to Ezine home page (for reading). Link to Blogging home page (to add comments). |
| ||||||||||
PH: 01144 1225 708225 • FAX: 01144 1225 707126 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho | |||||||||||