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)) |
Tcl - a new example for data reformatting
Tcl is an excellent language for combing through and reformatting data - though rarely a first choice language for such tasks if users aren't doing other things with it too.
Towards the end of last week's Learning to program in TCL course, a "side task" requirement came up to reformat our course diary into a .csv file so that a reseller who sells our courses to fill gaps / niches in his own more generic schedule.
Data of the form
30,11,2015 EL 8
needs to be transformed into data of the form
ELFULL,30/11/2015,09:00,04/12/2015,17:00,Standard,1,1,SN12 7NY,En-GB,1350,1350,GBP,Well House,Learning to Program in Perl,Other (IT)Code
Complete program [here] and sample data [here].
The main code is as simple as
loadDataWH "diary" intoHere
saveDataQA "qa.csv" intoHere
so you can see that even in Tcl, we're using good, structured programming techniques - in this case letting me provide a number of different input formats and a number of output genereators.
Other points of note ...
• calculating end date from start date, allowing for month and year ends:
set starts [clock scan "$day,$month,$year 12 00" -format "%d,%m,%Y %H %M"]
set ends [expr $starts + ($courselength -1) * 3600 * 24]
set eday [clock format $ends -format %e]
set emonth [clock format $ends -format %m]
set eyear [clock format $ends -format %Y]
reduces day, month, year of start to seconds from 1.1.1970, adds the number of days of the course (*3600*24) to make it seconds, and converts back. Much easier than trying to work out month lengths, especially for February in leap years.
• course names ending in "P" are 4 days and "L" are five days:
set courselength 5
set courseformat {Learning to Program in %s}
if {[regexp {P$} $coursecode]} {
set courselength 4
set courseformat {%s Programming}
}
• use of upvar to pass big chunks of data out of and into procs effectively and easily.
• allowing blank lines on input to be ignored
if {[string length $lyne] < 1} continue
• ... and many other useful techniques, worth a study!
(written 2015-10-10)
Associated topics are indexed as below, or enter http://melksh.am/nnnn for individual articles T209 - Tcl/Tk - File and Directory Handling [779] The fragility of pancakes - and better structures - (2006-06-26) [785] Running external processes in Tcl and Tcl/Tk - (2006-06-29) [1407] Reading from another process in Tcl (pipes and sockets) - (2007-10-26) [1426] Buffering up in Tcl - the empty coke can comparison - (2007-11-10) [1467] stdout v stderr (Tcl, Perl, Shell) - (2007-12-10) [2467] Tcl - catching an error before your program crashes - (2009-10-22) [3192] Tcl - Some example of HOW TO in handling data files and formats - (2011-03-04) [3320] Reading the nth line from a file (Perl and Tcl examples) - (2011-06-09) [3429] Searching through all the files in or below a directory - Ruby, Tcl, Perl - (2011-09-09) [3617] The fileutil package and a list of file system commands in Tcl - (2012-02-18) [4461] Reading from a URL, and reading Json, from your Tcl script - (2015-03-12) [4523] Catching failed commands and not crashing the program in Tcl - (2015-10-10)
Some other Articles
Routing in FlaskHello Flask world / Python web micro frameworkDay trip to LancasterWhat does Tcl do if you try to run a command that is not defined?Tcl - a new example for data reformattingLoading packages in your Tcl programShould we get an AA or Visit Wiltshire hotel assessment?No cold sales calls please - but delighted to hear from others!Course Schedule - October 2015 to June 2016
|
4759 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, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96 at 50 posts per page
This 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).
|
|