PeterKaagman has asked for the wisdom of the Perl Monks concerning the following question:
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:
and try to parse that with the following code:Naam,Adres,Woonplaats Peter,Liër,ôlsten
which results in the following output:#! /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);
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.$VAR1 = [ { 'Woonplaats' => "\x{f4}lsten", 'Adres' => "Li\x{eb}r", 'Naam' => 'Peter' } ];
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
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Text::CSV_XS and encoding
by tangent (Parson) on Sep 16, 2018 at 23:28 UTC | |
by PeterKaagman (Sexton) on Sep 17, 2018 at 17:17 UTC | |
by Tux (Canon) on Sep 17, 2018 at 20:54 UTC | |
Re: Text::CSV_XS and encoding
by poj (Abbot) on Sep 16, 2018 at 15:05 UTC | |
by PeterKaagman (Sexton) on Sep 16, 2018 at 19:52 UTC | |
by poj (Abbot) on Sep 16, 2018 at 20:37 UTC | |
by PeterKaagman (Sexton) on Sep 16, 2018 at 15:58 UTC | |
by Tux (Canon) on Sep 17, 2018 at 06:31 UTC | |
by PeterKaagman (Sexton) on Sep 17, 2018 at 17:23 UTC | |
by poj (Abbot) on Sep 17, 2018 at 20:42 UTC | |
Re: Text::CSV_XS and encoding
by BillKSmith (Monsignor) on Sep 16, 2018 at 20:21 UTC | |
Re: Text::CSV_XS and encoding
by bliako (Monsignor) on Sep 16, 2018 at 22:43 UTC | |
Re: Text::CSV_XS and encoding
by PeterKaagman (Sexton) on Sep 17, 2018 at 21:29 UTC | |
by Tux (Canon) on Sep 18, 2018 at 06:49 UTC |
Back to
Seekers of Perl Wisdom