http://qs321.pair.com?node_id=1222481


in reply to Text::CSV_XS and encoding

The Data::Dumper output is correct, but it is showing the escaped characters - for example \x{f4} is the "latin small letter o with circumflex".

I suggest you try printing to a file like this:

open my $in, "<:encoding(UTF-8)", "in_file.csv" or die "in_file.csv $!"; my $aoh = csv( in => $in ); close $in; open my $out, ">:encoding(UTF-8)", "out_file.txt" or die "out_file.txt $!"; for my $hash (@$aoh) { while (my($key,$val) = each %$hash) { print $out "$key => $val\n"; } } close $out;

Replies are listed 'Best First'.
Re^2: Text::CSV_XS and encoding
by PeterKaagman (Sexton) on Sep 17, 2018 at 17:17 UTC

    Curious....

    Had to adapt your example a bit: you do need the "headers => 'auto'" to make the result an array of hashes.. put the output to the console and the file. On the console it is again screwed (did indeed try that before)... but vim reads out.txt just fine (did not try that before).

    Console:

    1.36 Naam => Peter Woonplaats => &#9618;lsten Adres => Li&#9618;r
    File
    Naam => Peter Woonplaats => ôlsten Adres => Liër

    Goal is to put the values of 4500 students and 600 staf members in a database... so I'll go ahead with that. See how it turns out

    For the curious: The ultimate goal is an interface which sits between our school information system and Microsofts School Data Sync. C# and Delphi were suggested as tooling. I went ahead with Perl

      >binmode STDOUT, "encoding(utf-8)"; to the rescue.


      Enjoy, Have FUN! H.Merijn