Thank you very much for your replies / comments Dave, Ken and ikegami!
"use utf8;" seems to do the job which surprises me as I probably misunderstood what it does.
Besides the - hopefully - solution provided by all I appreciate the side suggestions made.
'\xE4 was a typo I cut off the rest: '\xE4lter ...'
Posting SSCCE code is a bit of a challenge for me as my problem is the data inserted into the database.
I am always suspicious of what kind of data I have in the database in the end,
even if it looks correct at first sight. At the moment it looks correct and with other approaches I get errors.
The source file imported is encoded in UTF-8.
#!/usr/bin/perl
use utf8;
use open IN => ':encoding(UTF-8)';
open (DATA, "source.txt") || die "error opening file";
while (<DATA>) {
my $add;
if ($_ =~ /behälter/i) {
$add->{Category} = 'Resttonerbehälter';
$add->{Description} = $_;
}
my $added = $DB->table('tablename')->add($add);
}
close DATA;
The values of $add->{Category} and $add->{Description} are both inserted into a database with latin1_swedish_ci collation.
I would have expected these values to cause problems with the "use utf8;" but it seems like they are latin1 and I guess if I would want them to be UTF-8 I would have to encode them and the encoding of the strings have nothing to do with "use utf8;".
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.