in reply to Re^4: Text::CSV encoding parse()
in thread Text::CSV encoding parse()
I don't see any mention of any encoding in this code, which is not good. And earlier you said: "I'm using the CGI module and have it properly set: print $q->header(-charset => 'utf-8');" so I doubt this code is representative.
You need to:
- Use a Perl version >= 5.12 and say use feature 'unicode_strings'; or use 5.012; (or higher).
- If you have any non-ASCII characters in your Perl script, save it as UTF-8 and add the use utf8; directive at the top.
- Make sure your data is coming from the database properly encoded. As I linked to above, you can check this via Devel::Peek. If you need that output to go to the browser, see this.
- Make sure you are doing binmode STDOUT, ':encoding(UTF-8)'; or use open qw/:std :utf8/;.
- Make sure you are telling your browser what encoding you are sending it.
Text::CSV is not the problem:
use warnings; use strict; use Devel::Peek; use Text::CSV; my $str = "\N{U+20AC}|\N{U+20AC}"; Dump($str); # ... UTF8 "\x{20ac}|\x{20ac}" ... my ($s1,$s2) = split /\|/, $str; Dump($s1); # ... UTF8 "\x{20ac}" ... Dump($s2); # ... UTF8 "\x{20ac}" ... my $csv = Text::CSV->new ({ binary => 1, sep_char => "|" }); $csv->parse($str); my ($c1,$c2) = $csv->fields; Dump($c1); # ... UTF8 "\x{20ac}" ... Dump($c2); # ... UTF8 "\x{20ac}" ...
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^6: Text::CSV encoding parse()
by slugger415 (Monk) on Aug 14, 2019 at 21:41 UTC | |
by haukex (Bishop) on Aug 15, 2019 at 06:43 UTC | |
by Tux (Abbot) on Aug 15, 2019 at 07:53 UTC | |
by haukex (Bishop) on Aug 15, 2019 at 08:26 UTC | |
by slugger415 (Monk) on Aug 16, 2019 at 18:35 UTC | |
by haukex (Bishop) on Aug 17, 2019 at 06:47 UTC | |
by slugger415 (Monk) on Aug 20, 2019 at 17:25 UTC | |
| |
by jcb (Parson) on Aug 14, 2019 at 23:16 UTC |
In Section
Seekers of Perl Wisdom