Reputation: 1
I have a set of russian string which I am passing as a input to a perl script to store the same into database but when I print the same string on windows console I get characters from input. Also, the database has different characters inserted in the column. Could you please share some pointers for the issue.
Upvotes: 0
Views: 356
Reputation: 385917
Decode inputs. Encode outputs.
What's the encoding of the data in your database?
Say it's UTF-8. You'd use something like the following:
use Encode qw( decode );
my $row = ...;
$row->{text_field} = decode('UTF-8', $row->{text_field});
What's the encoding expected by your console?
You can find the answer to this by running chcp
at the prompt, and prepending cp
to the number. For example, on a machine where the encoding to use is cp437
, you'd ge tthe following output:
>chcp
Active code page: 437
You'd handle the encoding as follows:
use open ':std', ':encoding(cp437)';
Upvotes: 1