When I extract data from a MySQL database, some of the output have special characters,
when opened in e.g. emacs it decodes to \240
and \346
.
When shown in an UTF-8 terminal, the special characters is shown as �
So the used encoding seams to only use 1 byte per character.
I can e.g. see that \346
should be æ
.
Question
Does Perl have a module that can encode these special characters to UTF-8?
Use Encode::decode
to decode your data from whatever encoding it's in to Perl's internal format.
Then, when writing the data out to a file, set the 'utf8'
layer to make the data be written in UTF-8.
use Encode;
my $data_from_database = ...;
my $perl_data = decode('ISO-8859-1', $data_from_database);
binmode STDOUT, ':utf8';
print $perl_data;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With