October 2014
Intermediate to advanced
280 pages
7h 20m
English
Write a sigil ~v that parses multiple lines of comma-separated data, returning a list where each element is a row of data and each row is a list of values. Don’t worry about quoting—just assume each field is separated by a comma.
| | csv = ~v""" |
| | 1,2,3 |
| | cat,dog |
| | """ |
would generate [["1","2","3"], ["cat","dog"]].
The function Float.parse converts leading characters of a string to a float, returning either a tuple containing the value and the rest of the string, or the atom :error.
Update your CSV sigil so that numbers are automatically converted.
| | csv = ~v""" |
| | 1,2,3.14 |
| | cat,dog |
| | """ |
should generate [[1.0,2.0,3.14], ["cat","dog"]].
(Hard) Sometimes ...
Read now
Unlock full access