ELISHEVA has asked for the wisdom of the Perl Monks concerning the following question:
I have a bom prefixed file that I'd like DBD::CVS (v. 0.49) to read and query, but when I tried I kept getting the error message Execution ERROR: Missing first row due to EIF - Loose unescaped quote . But there are no unquoted fields and the only thing I can think is happening is that it sees the BOM and thinks the first field of the first row begins without a quote. (For those not familiar with the DBD::CSV documentation "Loose unescaped quotes" are quotes embedded in a field that begins without a quote).
I'm fairly certain the problem is the BOM because if I remove the BOM, the file can be read and loaded without error
What's puzzling is that the underlying Text::CSV_XS module is BOM friendly. I've tried a variety of things to no avail, among them:
- setting f_encoding => 'utf8'
- setting csv_detect_bom => 1 and detect_bom => 1 in hopes that it would be passed onto the underlying Text::CSV_XS module
- using an explicit column list (via col_names) and skipping the first line via csv_skip_first_row
- setting csv_allow_loose_quotes => 1. That suppresses the EIF error message but replaces it with complaints that the column name stored in the first field in the first line doesn't exist - adding to my suspicions that it thinks the BOM is part of the field name
I had considered just removing the BOM and ignoring the problem, but this isn't a one-off. A data source I don't control is producing these BOM prefixed files. I'd rather not be manually munging files (even with a script), every few months. Furthermore the source, or one of them, is the OECD. They produce a lot of data and I'd like that data to be accessible to other Perl programmers in CSV format, either through the solutions we discuss on this thread or because DBD::CSV has been enhanced to be BOM friendly.
Many thanks in advance