29 lines
		
	
	
		
			726 B
		
	
	
	
		
			Markdown
		
	
	
	
	
	
			
		
		
	
	
			29 lines
		
	
	
		
			726 B
		
	
	
	
		
			Markdown
		
	
	
	
	
	
| # CSV Module
 | |
| 
 | |
| Functions for operating over CSV data.
 | |
| 
 | |
| ### each-record
 | |
| 
 | |
| ```
 | |
| csv:each-record FILE BLOCK
 | |
| ```
 | |
| 
 | |
| Opens the CSV file at FILE and calls BLOCK on each record. It is expected that this
 | |
| CSV file has a header which appears as the first row. This command will read and
 | |
| index the header, then start calling BLOCK from the row directly below the header.
 | |
| 
 | |
| BLOCK is called with the arguments _|row header|_ where:
 | |
| 
 | |
| - _row_ contains the fields of the current row as a list.
 | |
| - _header_ contains a hash mapping a header name to a field index.
 | |
| 
 | |
| The return value will be nil.
 | |
| 
 | |
| ```
 | |
| csv:each-record "winds.csv" { |row hdr|
 | |
|   set name $row.($hdr.name)
 | |
|   set bearing $row.($hdr.bearing)
 | |
|   
 | |
|   echo "Wind $name has bearing $bearing"
 | |
| }
 | |
| ``` |