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}" ...
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, 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, 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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.
|
|