Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

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

In reply to DBD::CSV - how to I coax it to read BOM prefixed files? by ELISHEVA

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?

What's my password?
Create A New User
Domain Nodelet?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (1)
As of 2023-09-24 20:14 GMT
Find Nodes?
    Voting Booth?

    No recent polls found