Skip to content

Instantly share code, notes, and snippets.

@cmosguy
Created April 8, 2016 19:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cmosguy/b3c34ae24ac3ff99bb7e37f8c7eed352 to your computer and use it in GitHub Desktop.
Save cmosguy/b3c34ae24ac3ff99bb7e37f8c7eed352 to your computer and use it in GitHub Desktop.
package require csv
package require struct::matrix
proc parseCsv {csvFile} {
catch {
#doing a lot of reloading on the data matrix
#need to delete the data command before issuing the
#struct command again
rename data {}
}
::struct::matrix data
set chan [open $csvFile r]
csv::read2matrix $chan data , auto
close $chan
puts "Processing CSV: $csvFile"
set rows [data rows]
puts "Total rows: $rows"
for {set row 0} {$row < $rows} {incr row} {
set dataRow [data get row $row]
puts "row $row: $dataRow"
}
#remember to destroy the matrix!!!!
data destroy
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment