Hi there monks

The last couple of days I've been playing around with Text::CSV_XS to import some csv data. Which goes quite well up to the point where I encounter special characters.

I've made myself a test file:

Naam,Adres,Woonplaats Peter,Liër,ôlsten
and try to parse that with the following code:
#! /usr/bin/perl -w use strict; use Text::CSV_XS qw( csv ); use Data::Dumper; my @rows; open my $FH, "<", "./test2.csv" or die "./test.csv $!"; my $aoh = csv( in => $FH, headers => 'auto' ); close $FH; print Dumper($aoh);
which results in the following output:
$VAR1 = [ { 'Woonplaats' => "\x{f4}lsten", 'Adres' => "Li\x{eb}r", 'Naam' => 'Peter' } ];
I tried to resolv this by putting an encoding on the file open like "<:encoding(UTF-8)" or by adding "encoding => 'UTF-8' to the csv parameters. Neither have the desired effect.

Perhaps a complete new problem, allthough I think it has something to do with it: The stream I need to parse (originally) has some jibbrish at the start. I think that is a BOM. So I tried to put "detect_bom => 1" to the csv parameters as the man pages suggests. This results in an error:

# CSV_XS ERROR: 1000 - INI - Unknown attribute 'detect_bom' @ rec 0 po +s 0 INI - Unknown attribute 'detect_bom' at ./parse.pl line 12. shell returned 25

Could anyone shine a light on this for me?

Peter


In reply to Text::CSV_XS and encoding by PeterKaagman

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



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.