[m-users.] Read csv file with variable number and type of fields
Dirk Ziegemeyer
dirk at ziegemeyer.de
Wed Sep 2 03:11:02 AEST 2015
Dear all,
I need to read csv files where the number and the type of fields in a record is not fixed in advance. Instead the record structure is determined by the header record of the csv file together with a database which assigns a data type to every header field name.
I’m wondering if I can use the library https://github.com/juliensf/mercury-csv for that.
It seems that I need to know the record structure in order to initialize a csv reader with csv.init_reader/3.
My idea is to read the file in two steps:
1. the header line (in order to determine number and type of fields), e.g. with some DCG rules or module parsing_utils
2. the rest
Is this a valid approach and can I combine io.read_line_as_string/3 to read the header line and stream.get/4 to read the rest of the file?
Thanks,
Dirk
More information about the users
mailing list