I have been playing with various csv import methods and decided to stick to the 'standard' tcllib packages of csv and struct::matrix because they are fairly smart and good enough for what I need. I ran into two obstacles, so here' what I did for any others who may follow. After mucking around trying to get the standard tcllib to work, I just ran [ns_info tcllib] and decided to copy the csv.tcl and matrix.tcl files into that tcllib area. At that point my package requires worked fine. CSV was totally fine, there was a subtle behaviour on the struct::matrix library - it works like tdom does - you don't create a variable to hold the data, but rather, a proc that has various methods of munging its contents.
By default you call struct::matrix newMatrixName and create a matrix proc. Unfortunately it gets tangled in the current namespace, which is template:: in most OpenACS pages. I couldn't say struct::matrix somenamespace::newMatrixName - the method below inside the namespace eval is what ended up working properly across multiple invocations. Note also that it doesn't disappear. You can either newMatrixName destroy at the end of the script or do so the next time through as I have done below.
What is omitted below is the ad_return_template and various other "regular" Openacs page things ..
Having said that - the struct library shows great promise!
package require csv
package require struct
set str6 {666,"123,521.2",001,"Mary says ""Hello, I am Mary"""}
set str7 {777,"123,521.2",001,"Mary says ""Hello, I am Mary"""}
catch {
foobar::someCSV destroy
}
namespace eval ::foobar:: {
struct::matrix ::foobar::someCSV
#struct::matrix someCSV -- will work also
}
csv::split2matrix foobar::someCSV $str6 "," auto
csv::split2matrix foobar::someCSV $str7 "," auto
set numcols [foobar::someCSV columns]
set numrows [foobar::someCSV rows]
set count "$numcols and $numrows"
set output [foobar::someCSV format 2string ]